Skip to content

Instantly share code, notes, and snippets.

@rubyworks
Created January 24, 2010 08:23
Show Gist options
  • Save rubyworks/285097 to your computer and use it in GitHub Desktop.
Save rubyworks/285097 to your computer and use it in GitHub Desktop.
OpenHash is a hash with a #method_missing that routes to [] and []=.
# OpenHash is a hash with a #method_missing method
# that routes to [] and []=.
class OpenHash < Hash
def method_missing(s, *a)
case s
when /\?$/
self.key?(s.chomp('?'))
when /\=$/
self[s] = a[0]
else
a.empty? ? self[s] : super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment