PDA

View Full Version : Made it to page 27


richard
September 21st, 2005, 11:49 PM
Starting the book "programming ruby" This doen't return what the author states. I've changes the vaiables but nothing else. Any thoughts?

class Song
def initialize(name, artest, duration)
@name = name
@artest = artest
@duration = duration
end
end

Song = Song.new("Over My Head", "The Fray", 356)
Song.inspect


produces
>ruby song.rb
song.rb:9: warning: already initialized constant Song
>Exit code: 0

steve_d555
September 21st, 2005, 11:55 PM
You shouldn't name the variable the same as the class. Try

song = Song.new("Over My Head", "The Fray", 356)
puts song.inspect

richard
September 22nd, 2005, 12:15 AM
The book left out "puts", maybe it was assumed. Having the difference between the class and the variable being a small s verses a capital S was hard to see in the book.