Ruby inner method visibility bug
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
def foo | |
def bar | |
end | |
end | |
foo | |
p Object.instance_methods(false) | |
p Object.private_instance_methods(false) |
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
# in ruby 1.9.2p320, foo and bar are private: | |
$ ruby bug.rb | |
[] # public instance methods | |
[:foo, :bar] # private instance methods | |
# in ruby 1.9.3p194, foo is private, but bar is public | |
$ ruby bug.rb | |
[:bar] # public instance methods | |
[:foo] # private instance methods |
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
# The same problem exists inside of a class definition | |
class Foo | |
private | |
def foo | |
def bar | |
123 | |
end | |
end | |
end | |
f = Foo.new | |
f.send(:foo) | |
p Foo.instance_methods(false) | |
p Foo.private_instance_methods(false) |
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
# 1.9.2p320 | |
$ ruby bug_class.rb | |
[] # public | |
[:foo, :bar] # private | |
# 1.9.3p194 | |
$ ruby bug_class.rb | |
[:bar] # public | |
[:foo] # private |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment