Created
February 22, 2012 10:13
-
-
Save hipe/1883962 to your computer and use it in GitHub Desktop.
super() with blocks -- how to avoid them bubbling up?
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
#!/usr/bin/env ruby -w | |
class Foo | |
def foo &block | |
block.call "i am foo" | |
end | |
end | |
class Bar < Foo | |
def foo &block | |
super() | |
block.call "i am bar" | |
end | |
end | |
Bar.new.foo { |s| puts "hello: #{s}" } | |
# outputs: | |
# hello: i am foo | |
# hello: i am bar | |
# how can you explicitly prevent the block from cascading up in the call to super? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment