Next | 1.2 Simple project | Prev |
class Song attr_reader :title, :album, :artist def initialize(filename) @artist, @album, @title = filename.split("/")[-3..-1] @title.chomp!(".ogg|.mp3") end def <=>(other) title <=> other.title end def to_s "#{@title}, #{@artist} - #{@album}" end end song1 = Song.new("/data/music/Bela Fleck/Drive/White Water.ogg") song2 = Song.new("/data/music/ABBA/The Best of/Chiquitita.ogg") puts [song1, song2].sort
Chiquitita, ABBA - The Best of White Water, Bela Fleck - Drive
Next | Ruby for Perl programmers | Prev |