-2

我收到错误消息

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}"
4

1 回答 1

2

您在代码中错过了右大括号()zipcode = clean_zipcode(row[:zipcode]。将其重新编写为zipcode = clean_zipcode(row[:zipcode]).

于 2013-08-06T20:16:36.103 回答