我似乎无法弄清楚这一点。我有以下课程:
class CSV_Email
attr_accessor :client_array, :email_array
def load(file)
@file = file
#Parse csv file into ruby arrays...
#Column Headers - Email, Client
@client_array = []
@email_array = []
CSV.foreach(file, :col_sep => ",", :headers => :first_row, :return_headers => false) do |column|
client_array << column[0]
email_array << column[1]
end
end
end
现在我需要访问client_id_array
和email_array
。我试过这个:
test = CSV_Email.new
test.load("Email_Test.csv")
puts client_array
但我收到undefined local variable client_array
错误。我该如何访问该变量?
我正在使用ruby 1.9.3。
答案 0 :(得分:4)
您需要使用您创建的对象:
puts test.client_array