Last active
July 12, 2020 00:13
-
-
Save patmaddox/1cc03cbda74a0cd9781e689cc282ae72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def or_else | |
self | |
end | |
end | |
class NilClass | |
def or_else | |
yield | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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