Thursday, December 13, 2007

Hash Math: + and -

I wrote some simple code which allows you to use plus and minus signs on Hashes in Ruby.

From the spec:

it "should add hashes" do
({:a => :b} + {:c => :d}).should == {:a=>:b, :c=>:d}

it "should subtract hashes" do
({:a=>:b, :c=>:d} - {:c => :d}).should == {:a => :b}

I'm kinda surprised this didn't exist already.

Here's the code; here's the spec. Both are in Utility Belt's Subversion repo, and should be available in an upcoming version.