Created
September 14, 2010 02:10
-
-
Save liwh/578413 to your computer and use it in GitHub Desktop.
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 | |
def method_missing(method, *params) | |
#首先得把symbol转化成string,如h={}.h.a = 1,此时,method 就为:a= | |
method_string = method.to_s | |
if method_string[-1] == 61 | |
self[method_string[0..-2]] = params.first | |
else | |
self[method_string] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment