require "csv"
class EventManager
def initialize
puts "EventManager Initialized."
filename = "event_attendees.csv"
@file = CSV.open(filename)
end
def print_names
@file.each do |line|
puts line[2]
end
end
def print_names2
@file.each do |line|
puts line[1]
end
end
end
manager = EventManager.new
manager.print_names
manager.print_names2
大家帮忙看看,只有第一个方法有输出,第二个就没了 puts @file 显示是同一个对象 如果每个方法都先 open file 的话是可以的,但是为什么每次 open 只能读取一次呢