Last active
June 3, 2020 12:36
-
-
Save hadrienblanc/ffeed01a086e08cedd22f0e729eb6679 to your computer and use it in GitHub Desktop.
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
class Test | |
def run | |
upload { puts "YIELD" } | |
end | |
def run2 | |
upload do | |
puts "yield with do" | |
end | |
end | |
def run3 | |
a_proc = Proc.new { puts "yield from proc.new" } | |
upload(&a_proc) | |
end | |
def run4 | |
upload(&method(:a_method)) | |
end | |
def a_method | |
puts "yield from a method" | |
end | |
def upload(&block) | |
puts "before the block" | |
yield | |
puts "after the block" | |
end | |
end | |
Test.new.run | |
Test.new.run2 | |
Test.new.run3 | |
Test.new.run4 | |
Proc.new | |
class FakeBundle | |
def pass_yield(&block) | |
generate(&block) | |
end | |
def generate | |
yield('file1.mp3') | |
yield('artwork.png') | |
end | |
end | |
FakeBundle.new.pass_yield do |file| | |
puts file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment