Skip to content

Instantly share code, notes, and snippets.

View JosimarCamargo's full-sized avatar

Josimar Camargo JosimarCamargo

View GitHub Profile
@JosimarCamargo
JosimarCamargo / defaults.rb
Created September 5, 2018 18:16 — forked from stevenharman/defaults.rb
A subtle difference between Ruby's Hash.fetch(:key, :default) vs. (Hash[:key] || :default)
h = {
'a' => :a_value,
'b' => nil,
'c' => false
}
h.fetch('a', :default_value) #=> :a_value
h.fetch('b', :default_value) #=> nil
h.fetch('c', :default_value) #=> false
h.fetch('d', :default_value) #=> :default_value