Skip to content

Instantly share code, notes, and snippets.

@hipe
Created February 22, 2012 10:13
Show Gist options
  • Save hipe/1883962 to your computer and use it in GitHub Desktop.
Save hipe/1883962 to your computer and use it in GitHub Desktop.
super() with blocks -- how to avoid them bubbling up?
#!/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