Ruby Actually Does Stuff

Ruby was originally created as a multi-paradigm language. Recently, it's just been a web programming language, thanks to Ruby on Rails. While it's not a bad thing, and has certainly shot Ruby into the mainstream programming community, what about the other parts? What about systems coding?

Well, look no further. I looked and noticed I didn't have the tree command installed on my Xubuntu box, and decided this would be as good a test as any for the workhorse. I fired up gedit and away I went! After only about fifteen or twenty minutes, I'd pounded out a working version. Half an hour after I started (two revisions later), it had all the features I needed: symlink location (but not following) and the full tree structure.

Speed isn't really an issue; most of the speed is just printing. My 160GB external drive takes around 2.2 seconds to display, on average. Here's a fairly representative run:

hr4dish@home/hr4dish$ time tree /media/external
# ..snip snip...
|   |       `-- The Red Jumpsuit Apparatus - Face Down.mp3
|   `-- David Crowder Band/
|       `-- B Collision/
|           |-- 07 - I Saw the Light (live with Robbie Seay and Shane & Shane).mp3
|           |-- 06 - Be Lifted (live with Robbie Seay and Shane & Shane).mp3
|           |-- 01 - Intro (I've Had Enough).mp3
|           |-- 04 - Everybody Wants to go to Heaven (LP).mp3
|           |-- 03 - Wholly Yours - B Variant.mp3
|           |-- 02 - A Beautiful Collision - B Variant.mp3
|           `-- 05 - I Can Hear the Angels Singing (...andeverandeverand...).mp3
`-- lost+found/

real    0m1.918s
user    0m0.376s
sys     0m0.196s

That's damn good for a scripting language that just traversed 30 gigabytes' worth of data.

It's available on GitHub, courtesy of their handy Gist service: http://gist.github.com/337016