Timothy Byrd
2/23/2005 10:00:00 PM
Csaba Henk wrote:
> In the first case, the expression returns the array you need, but c
> won't refer to that array.
Huh? Oh. My fault - I was using #flatten! and failed to copy/paste the
bang sign. That should assign to c, since #insert is also
self-modifying (hard to use the word "destructive" here).
Anyway, yeah, a #find_index method would have been handy. But now, I
may not need it (see below). And it's a beauty of Ruby that if I do
need it in the future, I should simply be able to extend either Array
or Enumerable.
William James wrote:
> irb(main):002:0> "Loreena Sue McKennitt".sub(/(.*) (.*?)$/,'\2, \1')
> => "McKennitt, Loreena Sue"
True, but I still want to sort "Jethro Tull" under the 'J's. :)
Also in certain cases, I want to change how an artist or album title
appears in my list. As an example I want "Kim Robertson and Virginia
Kron / Gratitude" to appear as "Kim Robertson - Gratitude" so I can put
her albums in chronological order.
I got it working (except for a final tweak to the list format) last
night - and then realized I was stupid. I'd gone so far as to make a
script to gather all my custom comments into a text file, so I could
re-apply them to the database. At that point, I thought, why bother
modifying all the CDDB files, when I can just fold in my custom changes
when I make the list?
Time to simplify.
The last bit is a simple puzzle (did it in C years ago) - I just want
to find a clever Ruby-ish way to do it.
Given a list of albums:
albums = [
"Apocalyptica - Plays Metallica By Four Cellos",
"Kim Robertson - Gratitude",
"Synergy - Electronic Realizations For Rock Orchestra",
"Synergy - Sequencer",
"Synergy - Chords",
"Synergy - Games",
]
I want the list output to look like:
1.\tApocalyptica - Plays Metallica By Four Cellos
2.\tKim Robertson - Gratitude
\tSynergy:
3.\t- Electronic Realizations For Rock Orchestra
4.\t- Sequencer
5.\t- Chords
6.\t- Games
So if an artist has more than one album, I'll gather the albums under
the artist. It's close to trivial, and there are a ton of ways to do
this, so I'll have fun. First I'll write it in a C-like style, then
I'll try Ruby-ifying it.
-- Timothy