1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Hash def bind(relation) inject({}) do |bound, (key, value)| bound.merge(key.bind(relation) => value.bind(relation)) end end def slice(*attributes) inject({}) do |cheese, (key, value)| cheese[key] = value if attributes.include?(key) cheese end end end