Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nonowarn
Created May 3, 2010 07:52
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 nonowarn/387856 to your computer and use it in GitHub Desktop.
Save nonowarn/387856 to your computer and use it in GitHub Desktop.
javascript-like Hash in Ruby
class H
def initialize(hash) @hash = hash end
def method_missing(name, *args)
if name =~ /([^=]+)=$/
return @hash[$1.intern] = args.first
end
@hash[name] || @hash[name.to_s]
end
end
def H(hash) H.new(hash) end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment