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)
これが私がこれまでに持っているものです。曲名の長さを比較するコードを書こうとしています。