Yesterday I put out a little screencast showing some ways of Creating Ruby Hashes. James Edward Gray II pinged me on Twitter and basically said “Great screencast! Ooh, but you forgot this! Ooh, and this! And this!” and so of course there was nothing to do for it but invite him to do a pairing screencast with me.
This video is a bit of a weird hybrid. You get 7 minutes of podcall, then 18 minutes of screencast, then another 12 minutes of podcall. James shows off some of the “hot new awesomeness” of Ruby 1.9, and then points out that this awesomeness has been around for a couple of years and nobody’s using it, in spite of it having been in the current Pickaxe for nearly as long. Along the way we talk about regular expressions, testing dogma, and the importance of never squashing creativity in the open source community. All in all, an incredibly fun time for me. James threatened to come back and do another one with me on regular expressions, and I’m mentioning it here in writing so that everybody knows I plan on taking him up on that offer.
No podcast, because half of it is us typing into a shared screen session. But here’s the video. You may need to watch it on Vimeo or download it to see the font clearly.
Associative Arrays with James Edward Gray II from David Brady on Vimeo.

You don’t want to piss James off, I heard he has a mean right hook!
David, you have an awesome shiny skull, and a great radio voice!
Also, thanks for the vid, it was pretty cool.
*blush* Thank you!
For the pair-wise Hash literal, you’re simply missing an extra brace.
Hash[[[1, 2], [3, 4]]]becomes{1=>2, 3=>4}(in 1.8 and 1.9). It seems weird, but I guess the idea is that usually you writeHash[nested_array].Actually, yes and no–I had to chase down the scratch video I made and rewatch it to figure out what was going on. Turns out that Hash[[[1,2], [3,4]]] won’t work in 1.8.6… but DOES work in 1.8.7! That’s what threw me. I tend to not think of 1.8.7 as being a “real” ruby because all my production boxes are 1.8.6 or 1.9, but the laptop I was on when I made the screencast was on 1.8.7. Check your ruby version–if you’re on Ruby 1.8, I’ll wager your on a late patch revision of 1.8.7. Thanks!
Very informative screencast. I get the privilege of hearing JEG2 talk a lot and every time I do my mind is blown.
Oh, and David your screencast and the split-screen format with the code in the middle is absolutely perfect! I love it and look forward to more
Awesome! Thanks! I love the accidental serendipity that the screen appears in the movie right where we are looking on our monitors, so it looks like we’re looking at the screen in the video.
During the show I had the urge to bust open a random ruby pdf. I opened Ruby Best Practices and the first place I jumped to was a section on RegEx with JEGII’s name… weird..
http://dl.dropbox.com/u/5850974/jamesgrey.jpg
James when he said he’s “anti dogma” absolutely nailed it – and everything else.
Yeah. James does that. :-) I don’t know how to explain it any better than that, but he really does.
Curious: James mentioned that the pickaxe has “fallen out of favor a bit”..
So what has the slight edge in ‘favor’ these days?
Ignorance, I think.
I wish I was kidding. Maybe I need to be a bit less cynical? Dunno. It seems like a lot of people are coming to Ruby as their first language, and the Pickaxe will teach you the ins and outs of Ruby but not how to program. So I think maybe a lot of n00bs are shying away from it when they could be embracing it. Dunno. Maybe it’s time we wrote a new Ruby book? :-)
There’s a lot of Ruby books out there. I admit the pickaxe has always worked as a reference for me but lately ruby-doc.org seems to be just as useful. I can’t recall a single book that stands out in teaching people how to program. I’ve always learned by reading a lot of code and coding. Every day I come upon humbling lessons from blog posts and screencasts like yours. Excellent job by the way. REALLY looking forward to a regex screencast between you and James. One of these days I have to figure out how to extract the most utility out of POSIX regex’s. Thanks again.
Nice.
One thing about Sets. SortedSet is great, but keep in mind that it does what it says: Keeps the Set in sorted order.
Sometimes you need a Set that keeps its elements in “insertion” order, so that if you iterate through it, you get the order you want. In 1.9.2, the underlying store is the new Hash, where the keys are ordered by insertion.
But there is no such animal to my knowledge for 1.8.x.
So if you want an OrderedSet which will work across both Rubies, the cheap way is to leverage ActiveSupport’s OrderedHash . . . something like this: https://gist.github.com/912016