Skip to content

Instantly share code, notes, and snippets.

@sunny
Created October 8, 2008 16:09
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 sunny/15553 to your computer and use it in GitHub Desktop.
Save sunny/15553 to your computer and use it in GitHub Desktop.
# The infamous Monkey-Hash. Example:
# h = {}
# h.foo = "bar"
# h.foo # => "bar"
class Hash
def method_missing(method, *params)
key = method.to_s
if key =~ /=$/
key = key[0..-2]
raise if respond_to?(key)
self[key] = params.first
else
self[key]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment