Ruby Geektool和TextMate错误
在寒假期间,我给自己做了一些小项目,并试图编写一些可用于桌面的geektool脚本。这是我为ruby编写的,它在终端中工作,但当我在textmate中运行它时,我得到一个主机关闭错误,当我将它放在geektool中时,它将不会运行Ruby Geektool和TextMate错误,ruby,textmate,geektool,Ruby,Textmate,Geektool,在寒假期间,我给自己做了一些小项目,并试图编写一些可用于桌面的geektool脚本。这是我为ruby编写的,它在终端中工作,但当我在textmate中运行它时,我得到一个主机关闭错误,当我将它放在geektool中时,它将不会运行 #!/usr/bin/ruby require 'open-uri' require 'nokogiri' def fetch_xml() open("http://weather.yahooapis.com/forecastrss?w=2424766&am
#!/usr/bin/ruby
require 'open-uri'
require 'nokogiri'
def fetch_xml()
open("http://weather.yahooapis.com/forecastrss?w=2424766&u=f")
end
def parse_xml()
source = Nokogiri::XML(fetch_xml)
location = source.xpath("//yweather:location")
condition = source.xpath("//item//yweather:condition")
forecast = source.xpath("//item//yweather:forecast")
[location[0]['city'], location[0]['region'], condition[0]['temp'].to_i, condition[0]['text'], forecast[0]['high'], forecast[0]['low']]
end
def display_weather()
result = parse_xml()
print "#{result}\n"
end
display_weather
它在终端中运行,并给出正确的输出:[德克萨斯州休斯顿,64,多云,69,63]
但正如我前面提到的,它不会在textmate中运行,geektool中也不会显示任何内容。提前感谢您的帮助