Created
November 18, 2012 05:54
-
-
Save sferik/4103815 to your computer and use it in GitHub Desktop.
Baloney sandwich
This file contains hidden or 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
def baloney | |
puts "baloney" | |
end | |
def bread | |
puts "bread" | |
end | |
def sandwich(filling) | |
bread | |
filling | |
bread | |
end | |
sandwich(baloney) |
that's what I'd guess too.
Fixed it:
def baloney
puts "baloney"
end
def bread
puts "bread"
end
def sandwich(filling)
bread
filling.call
bread
end
sandwich(method(:baloney))
Hey @nate about the fix. Wouldn't it be more natural something like this?
def baloney
puts "baloney"
end
def bread
puts "bread"
end
def sandwich(&block)
bread
yield
bread
end
sandwich { baloney }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
baloney
bread
bread
because you run
puts "baloney"
before passing the result (which is nil) tosandwich
So, inside sandwich this happens