Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created July 6, 2012 15:32
Show Gist options
  • Select an option

  • Save itspriddle/3060918 to your computer and use it in GitHub Desktop.

Select an option

Save itspriddle/3060918 to your computer and use it in GitHub Desktop.
Why not Object#or
class Object
def or(fallback)
self || fallback
end
end
1.or :name
=> 1
nil.or :name
=> :name
false.or :name
=> :name
config.or({})
=> {}
config.or({})[:value]
=> nil
config = { value: 1 }
=> { :value => 1 }
config.or({})[:value]
=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment