Want to pick a certain set of key/value pairs from a Ruby hash? You might do this:

hash = {:foo => "bar", :bar => "baz", :baz => "boo"} hash.select { |k,v| [:foo, :bar].include?(k) } # returns [[:foo, "bar"], [:bar, "baz"]]

Kind of messy. We can do better by reopening the Hash class this way:

class Hash def pick(*values) select { |k,v| values.include?(k) } end end

Now our selection works like this:

hash = {:foo => "bar", :bar => "baz", :baz => "boo"} hash.pick(:foo, :bar) # returns [[:foo, "bar"], [:bar, "baz"]]

Ruby is a wonderful language. This is one small example of how having access to existing classes can be incredibly powerful. With this power comes great responsibility. Wield your power wisely.