Skip to content

Instantly share code, notes, and snippets.

@sr
Created September 1, 2008 21:06
Show Gist options
  • Save sr/8341 to your computer and use it in GitHub Desktop.
Save sr/8341 to your computer and use it in GitHub Desktop.
~ % ruby hash.rb
"foo"
nil
hash.rb:9:in `[]': PythonLike (PythonLike)
from hash.rb:14
hash = {:python => 'foo', :perl => 'bar', :ruby => 'spam'}
puts hash[:python].inspect
puts hash[:php].inspect
class PythonLike < Exception; end
class Hash
def [](key)
raise PythonLike unless self.has_key?(key)
super
end
end
puts hash[:java].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment