语法错误意外tIDENTIFIER

时间:2013-08-06 20:14:35

标签: ruby syntax

我收到错误消息

syntax error, unexpected tIDENTIFIER, expecting ')'
    leg = legislators_by_zipcode(zipcode)

执行以下代码时:

require 'csv'
require 'sunlight/congress'

Sunlight::Congress.api_key = "c..."

def clean_zipcode(x)
    x = x.to_s.rjust(5, "0")[0..4]
end

def legislators_by_zipcode(zipcode)
    legislators = Sunlight::Congress::Legislator.by_zipcode(zipcode)

    legislator_names = legislators.collect do |legislator|
        "#{legislator.first_name} #{legislator.last_name}"
    end

    legislator_names.join(", ")
end

contents = CSV.open "event_attendees.csv", headers: true, header_converters: :symbol
contents.each do |row|
    name = row[:first_name]

    zipcode = clean_zipcode(row[:zipcode]

   leg = legislators_by_zipcode(zipcode)

   puts "#{name} #{zipcode} #{leg}"

1 个答案:

答案 0 :(得分:2)

您错过了代码中的结束括号()zipcode = clean_zipcode(row[:zipcode]。请将其写为zipcode = clean_zipcode(row[:zipcode])