我是ruby初学者。我使用proc类,但我得到错误。Ruby错误:未定义的方法`each'for nil:NilClass(NoMethodError)
class Timeline
attr_accessor :tweets
def each(&block) # Block into the proc
tweets.each(&block) # proc back into the block
end
end
timeline = Timeline.new(tweets)
timeline.each do |tweet|
puts tweet
end
收到错误: -
`each': undefined method `each' for nil:NilClass (NoMethodError)
如何解决这个问题?请告诉我们!
你'@ tweets'变量是零 – Ilya