-
-
Save ignacy/8d0050e9f6221f8b874c to your computer and use it in GitHub Desktop.
Methods taking multiple blocks
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 Multiple | |
def multiple(success) | |
rand(2).odd? ? success.call : yield | |
end | |
end | |
i = Multiple.new | |
10.times do | |
i.multiple -> { puts "success" } { puts "fail"} | |
end |
This is what Ruby offers us for free. The goal was to improve on that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice trick for getting this syntax to work, but won't scale for more blocks.