I'm a beginner at programming and wrote a simple program:
class Chapter
def initialize
@text
@number
end
end
def new_chapter
tmp_chapter = Chapter.new
tmp_chapter.text = 'Chapter about ..'
tmp_chapter.number = '11'
end
puts new_chapter
puts ObjectSpace.each_object(Chapter) {|x| p x}
But I get this error:
test2.rb:10:in `new_chapter': undefined method `text=' for #<Chapter:0x200b830>
(NoMethodError)
from test2.rb:14:in `<main>'
So what did I do wrong? I know there are other ways to create a new instance but I want to do it this way! Thanks!