Hello World.
This is my first forum membership, and first post.
I am learning Ruby.
It seems to be a very elegant an encompassing OO language.
I'm reading Thomas & Hunt: Classes, Objects, and Variables on-line.
See attached.
Regarding the following by the authors, and attached I see no
correlation.
However I've had very good results with attr_accessor.
Please help.
class Song
def name
@name
end
def artist
@artist
end
def duration
@duration
end
end
aSong = Song.new("Bicylops", "Fleck", 260)
aSong.artist » "Fleck"
aSong.name » "Bicylops"
aSong.duration » 260
···
------------------
class Song
attr_reader :name, :artist, :duration
end
aSong = Song.new("Bicylops", "Fleck", 260)
aSong.artist » "Fleck"
aSong.name » "Bicylops"
aSong.duration » 260
Attachments:
http://www.ruby-forum.com/attachment/5878/TH_QA_1.doc
http://www.ruby-forum.com/attachment/5879/attr.rb
--
Posted via http://www.ruby-forum.com/.