私は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)
?私たちに教えてください!あなたがattr_accessor :tweets
を定義するとき
をご '@のtweets'変数は、このコードは動作しません – Ilya