I am just going through the pickacxe book and have a question about
attr_reader. Here is the sample class.
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
It says I can do the following-
I can do the following-
attr_reader :name, :artist, :duration
This is fine, but it says “The corresponding instance variables, @name,
@artist, and @duration, will be created automatically” (on Page 31)
attr_reader. I kinda thought that those variables are already created
“initialize” function is called. If I comment the initialize function
run it - I get an error.
So what does the author mean by that?
Thanks in advance,