Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created July 6, 2012 15:32
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 itspriddle/3060918 to your computer and use it in GitHub Desktop.
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