B
Bharat Ruparel
I am running the following code from Programming Ruby book on page 120:
class Song
include Comparable
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
@plays = 0
end
def <=>(other)
self.duration <=> other.duration
end
end
song1 = Song.new("My Way", "Sinatra", 225)
song2 = Song.new("Bicylops", "Fleck", 260)
puts song1 == song1
It is printing true for the puts song1 == song2 statement. How are
these two song objects equal?
Thanks in advance for your time.
Bharat
class Song
include Comparable
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
@plays = 0
end
def <=>(other)
self.duration <=> other.duration
end
end
song1 = Song.new("My Way", "Sinatra", 225)
song2 = Song.new("Bicylops", "Fleck", 260)
puts song1 == song1
It is printing true for the puts song1 == song2 statement. How are
these two song objects equal?
Thanks in advance for your time.
Bharat