From: "T. Onoma" Date: 2003-12-06T13:39:09+09:00 Subject: Re: rubynuby code critique request On Saturday 06 December 2003 03:12 am, Jeff Dickens wrote: > I tried using the wiki at rubygarden.org but it just made a mess... > probably not designed for things this big. > > Anyhow, here's a (longish) program I've written as my first "real" ruby > program. I'm reading from the "Programming Ruby" book at rubycentral.com, > and what do you know, I actually do have a jukebox of sorts. Actually it's > a radio station I do some work for. So I expanded the example code some. > Have a look and poke some holes. I think you're right, this is a little more than the intended use of the Wiki NubyCodeCritique ;-) Well, I'd say you've done dang well. I only noticed a few places you could be more concise, but nothing of major significance. At least as far as I can tell from just looking it over briefly. It works I take it? That's the most important thing! :-) Beyond that you may wish to explore a bit of unit testing. A few quick spot suggestions: You might want to put more of the string cleanup in the parsing of the file rather than the append method. Also in parsing a file like this all \s+ spaces can be reduced to a single space (as it stands it looks like you'll still retain multiple spaces in between strings). So try .gsub(/\s+/,' ') on the file as it is read in. It seems like you prefer "word" methods, but it is possible to do stuff like: class ArtistIndex def initialize @aindex = Hash.new(nil) end # instead of def aindex (anObject, artist) def []=(anObject, artist) @aindex[artist] = [] if @aindex[artist].nil? @aindex[artist].push(anObject) end # instead of def alookup(artist) def [](artist) @aindex[artist] end # if it were me i'd just call this #artists def listartists @aindex.keys.sort end end These make it work like a Hash, which it essentially is. In fact you could subclass Hash: class ArtistIndex < Hash ... def listartists self.keys.sort end end And then you'd get all the abilites of hash as well, though this might be more than you need/want. My two bits, HTH, T.