J
Jeff Rohrer
Hi, total noob here. I'm only on page 25 of the Pick Axe book and I'm a
little stuck:
I'm running Ruby version 1.8.4 on Windows XP Home Edition. I'm entering
code via irb.
Here's the problem: I enter the following code from the book:
class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def to_s
"Song: #@name--#@artist (#@duration)"
end
end
I successfully load the code using a file called song.rb here:
irb(main):008:0> load "c:/code/song.rb"
=> true
Now the book states that if I type in this:
song = Song.new("Bicylops", "Fleck", 260)
song.to_s
I should see this:
"Song: BicylopsFleck(260)"
But I'm not, I'm getting this:
irb(main):013:0> song = Song.new("Bicylops", "Fleck", 260)
=> #<Song:0x2c80440 @duration=260, @name="Bicylops", @artist="Fleck">
irb(main):014:0> song.to_s
=> "#<Song:0x2c80440>"
Obviously I'm still seeing the object ID when I should be seeing the
string. Any help will be appreciated.
Regards,
Jeff
little stuck:
I'm running Ruby version 1.8.4 on Windows XP Home Edition. I'm entering
code via irb.
Here's the problem: I enter the following code from the book:
class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def to_s
"Song: #@name--#@artist (#@duration)"
end
end
I successfully load the code using a file called song.rb here:
irb(main):008:0> load "c:/code/song.rb"
=> true
Now the book states that if I type in this:
song = Song.new("Bicylops", "Fleck", 260)
song.to_s
I should see this:
"Song: BicylopsFleck(260)"
But I'm not, I'm getting this:
irb(main):013:0> song = Song.new("Bicylops", "Fleck", 260)
=> #<Song:0x2c80440 @duration=260, @name="Bicylops", @artist="Fleck">
irb(main):014:0> song.to_s
=> "#<Song:0x2c80440>"
Obviously I'm still seeing the object ID when I should be seeing the
string. Any help will be appreciated.
Regards,
Jeff