Skip to content

Instantly share code, notes, and snippets.

@hannestyden
Created October 10, 2014 11:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hannestyden/9abd77048e044ecf6b86 to your computer and use it in GitHub Desktop.
Save hannestyden/9abd77048e044ecf6b86 to your computer and use it in GitHub Desktop.
class Hash
alias_method :[], :fetch # !> method redefined; discarding old []
end
h = {a: 1}
h[:a] # => 1
h[:b] rescue $! # => #<KeyError: key not found: :b>
h[:b, 2] # => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment