Created
February 19, 2016 09:18
-
-
Save AnatoliiD/7d9715fb49a77b386535 to your computer and use it in GitHub Desktop.
understanding Hash#fetch
This file contains 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
#!/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