Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Created October 2, 2010 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shepmaster/607721 to your computer and use it in GitHub Desktop.
Save shepmaster/607721 to your computer and use it in GitHub Desktop.
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