Ruby-HashSlice

Ruby-HashSlice was one of the first modules I ever put up on the RAA, back when I was still mostly using Perl for everything. One of the only things I missed about Perl when I used Ruby was the (fairly cryptic) way you can slice out parts of Hashes using slice notion:

my %stuff = ( 
	foo => 'bar',
	baz => 'bim',
	wicked => 'witch',
	dog => 'Toto'
  );
print "Dorothy-related stuff: " . 
	join( ', ', @stuff{'wicked', 'dog'} );
		

After a few years of using the module everywhere, I discovered Hash#values_at, which gave me most of the stuff I needed, with the exception of being able to assign back to the Hash in slice notation too:

stuff = {
	:foo => 'bar',
	:baz => 'bim',
	:wicked => 'witch',
	:dog => 'Toto'
  }
puts "Dorothy-related stuff: " + 
	stuff.values_at( :wicked, :dog ).join( ', ' )
		

Nowadays I don't find I need a slice much when thinking more Ruby-ishly, but I kept the last release online just in case anyone wants it. I'm not maintaining it anymore, and haven't really even looked at it in several years, but here it is: