Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Last active June 3, 2020 12:36
Show Gist options
  • Save hadrienblanc/ffeed01a086e08cedd22f0e729eb6679 to your computer and use it in GitHub Desktop.
Save hadrienblanc/ffeed01a086e08cedd22f0e729eb6679 to your computer and use it in GitHub Desktop.
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