Skip to content

Instantly share code, notes, and snippets.

@ryands
Created December 12, 2013 02:24
Show Gist options
  • Save ryands/7922304 to your computer and use it in GitHub Desktop.
Save ryands/7922304 to your computer and use it in GitHub Desktop.
Monkey patch for Hash fun.
class Hash
# This will favor :symbol keys over string keys
def method_missing (method, *args)
if has_key? method.to_sym
self[method.to_sym]
elsif has_key? method.to_s
self[method.to_s]
else
super
end
end
end
# {:a => 5}.a == 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment