Last active
August 29, 2015 14:01
-
-
Save AndrewO/9c93b250c5d887eb3885 to your computer and use it in GitHub Desktop.
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 A | |
attr_reader :val | |
def initialize(a, &b) | |
@val = a || (b ? b.call : :nada) | |
end | |
end | |
class B < A | |
def initialize(b) | |
super(b) | |
end | |
end | |
# A.new(true).val | |
# => true | |
# A.new(false) { :ok }.val | |
# => :ok | |
# B.new(true).val | |
# => true | |
# B.new(false).val | |
# => :nada | |
# B.new(false) { :oops }.val | |
# => :oops | |
# How did that happen? `super` implicitly passes block params along even if you don't | |
class C < A | |
def initialize(c) | |
super(c, &nil) | |
end | |
end | |
# C.new(false) { :ok }.val | |
# => :nada | |
# RUBY_DESCRIPTION | |
# => "ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: http://stackoverflow.com/questions/10541242/scrubbing-a-block-from-a-call-to-super/10541349#10541349