Created
December 12, 2013 02:24
-
-
Save ryands/7922304 to your computer and use it in GitHub Desktop.
Monkey patch for Hash fun.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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