Created
October 2, 2010 15:24
-
-
Save shepmaster/607721 to your computer and use it in GitHub Desktop.
This file contains 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(name, *args) | |
match = /get_(.*)/.match(name.to_s) | |
if match and match[1] | |
puts match[1] | |
self.class_eval do | |
define_method(name) do | |
return self[match[1]] | |
end | |
end | |
puts self.methods.sort | |
self.send(name) | |
end | |
match = /set_(.*)=/.match(name.to_s) | |
if match and match[1] | |
return self[match[1]] = args[0] | |
end | |
super | |
end | |
end | |
things = {'alpha' => 1, 'beta' => 2} | |
puts things.get_alpha | |
puts things.get_beta | |
things.set_gamma = 6 | |
puts things.get_gamma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment