Skip to content

Instantly share code, notes, and snippets.

@JosimarCamargo
Forked from stevenharman/defaults.rb
Created September 5, 2018 18:16

Revisions

  1. @stevenharman stevenharman created this gist May 28, 2013.
    15 changes: 15 additions & 0 deletions defaults.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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

    (h['a'] || :default_value) #=> :a_value
    (h['b'] || :default_value) #=> :default_value
    (h['c'] || :default_value) #=> :default_value
    (h['d'] || :default_value) #=> :default_value