Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Last active July 12, 2020 00:13
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 patmaddox/1cc03cbda74a0cd9781e689cc282ae72 to your computer and use it in GitHub Desktop.
Save patmaddox/1cc03cbda74a0cd9781e689cc282ae72 to your computer and use it in GitHub Desktop.
class Object
def or_else
self
end
end
class NilClass
def or_else
yield
end
end
RSpec.describe OrElseWhat do
describe 'nil.or_else { value }' do
it 'returns the value' do
expect(nil.or_else { 'chicken' }).to eq('chicken')
end
end
describe 'false.or_else { value }' do
it 'returns false' do
expect(false.or_else { 'chicken' }).to be(false)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment