Hi all,
I am really starting to get into ruby and I am currently reading the
PickAxe book and the Agile Rails book, but there is one part of classes
that I don’t understand and I can’t seem to find any reference to it.
Here is a basic class as defined in the Pickaxe book:
1: class Song
2: attr_writer :duration
3: end
My question is, what is the whole statement on line #2? I know what it
does, it creates a attribute-setting method for the “duration” variable,
but what I don’t understand is how it does it. When does that line of
code get executed?
I am used to doing classes in C++ and PHP where the only thing outside
methods and inside a class are class variable declarations. Is this a
way to make variable declarations with a method?
This seems to be a very common construct in Ruby and I want to
understand what it is and how to use it correctly. Thanks
Peer