我是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