Last active
August 29, 2015 14:07
-
-
Save lsegal/928c1ff1f68bd13b948c 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 Foo | |
def foo; "abc" end | |
# this default param should resolve at runtime to the #foo method call | |
def run(foo = foo) | |
p foo # print shadowed local var defaulting to attr value | |
end | |
end | |
puts "Testing #{RUBY_VERSION}:" | |
Foo.new.run | |
__END__ | |
$ rvm all do ruby test_method_shadow.rb | |
Testing 1.8.7: | |
"abc" | |
Testing 1.9.2: | |
"abc" | |
Testing 1.9.3: | |
"abc" | |
Testing 2.0.0: | |
"abc" | |
Testing 2.1.1: | |
"abc" | |
Testing 2.1.2: | |
"abc" | |
Testing 2.1.3: | |
"abc" | |
Testing 2.2.0: | |
nil | |
$ |
def foo
"abc"
end
foo = foo
puts "Testing #{RUBY_VERSION}:"
p foo
# Testing 2.0.0:
# nil
Well damn. I'd still consider this surprising, but I guess this makes it more consistent. Hmm. 😟
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is a good change - I was never sure what would happen if I did this.
A better change would be for it to throw an error.