Created
September 1, 2008 21:06
-
-
Save sr/8341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ % ruby hash.rb | |
"foo" | |
nil | |
hash.rb:9:in `[]': PythonLike (PythonLike) | |
from hash.rb:14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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