Skip to content

Instantly share code, notes, and snippets.

@indirect
Created May 4, 2010 05:03
Show Gist options
  • Save indirect/388981 to your computer and use it in GitHub Desktop.
Save indirect/388981 to your computer and use it in GitHub Desktop.
ruby hashes like JS objects
class Hash
def method_missing( msg, *args )
super unless args.empty?
if has_key?(msg)
[msg]
elsif has_key?(msg.to_s)
[msg.to_s]
else
nil
end
end
end
hash = {
:cats => "awesome",
"dogs" => "okay I guess?"
}
puts hash.cats
puts hash.dogs
puts hash.notakey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment