class Song
include Comparable
attr_accessor :song_name
def <=>(other)
@song_name.length <=> other.length
end
def initialize(song_name)
@song_name = song_name
@song_name_length = song_name.length
end
end
a = Song.new('Rock around the clock')
b = Song.new('Bohemian Rhapsody')
c = Song.new('Minute Waltz')
puts a < b
puts b >= c
puts c > a
puts a.between?(c,b)
这是我到目前为止所拥有的。我正在尝试编写比较歌曲名称长度的代码。