從這個例子逐字輸入代碼,並接收以下語法錯誤消息。請幫忙!!Noob和谷歌搜索代碼接收語法錯誤
https://github.com/visionmedia/google-search/blob/master/examples/web.rb
我的代碼:
require "rubygems"
require "google-search"
def find_item uri, query
search = Google::Search::Web.new do |search|
search.query = query
search.size = :large
search.each_response {print "."; #stdout.flush}
end
search.find {|item| item.uri =~ uri}
end
def rank_for query
print "%35s " % query
if item = find_item(/vision\-media\.ca/, query)
puts " #%d" % (item.index +1)
else
puts " Not found"
end
end
rank_for "Victoria Web Training"
rank_for "Victoria Web School"
rank_for "Victoria Web Design"
rank_for "Victoria Drupal"
rank_for "Victoria Drupal Development"
錯誤消息:
Ruby Google Search:9: syntax error, unexpected keyword_end, expecting '}'
Ruby Google Search:11: syntax error, unexpected keyword_end, expecting '}'
Ruby Google Search:26: syntax error, unexpected $end, expecting '}'
雖然我沒有低調,但因爲你是正確的,所以使用分號和單行有時候比將語句分成單獨的行更有意義。 –
我會嘗試使用一個單一的行,並將其分成單獨的行 - 我是一個noob,無論如何我需要這種做法! – user2876778
謝謝zeantsoi – user2876778