Skip to content

Instantly share code, notes, and snippets.

@AnatoliiD
Created February 19, 2016 09:18
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 AnatoliiD/7d9715fb49a77b386535 to your computer and use it in GitHub Desktop.
Save AnatoliiD/7d9715fb49a77b386535 to your computer and use it in GitHub Desktop.
understanding Hash#fetch
#!/usr/bin/env ruby
def param_method
puts 'I was called both times'
'result'
end
def block_method
puts 'I was called only once'
'result'
end
args = {a: 'result'}
args.fetch(:a, param_method)
args.fetch(:b, param_method)
args.fetch(:a) { block_method }
args.fetch(:b) { block_method }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment