Skip to content

Instantly share code, notes, and snippets.

@davidbalbert

davidbalbert/bug.rb

Created Jun 22, 2012
Embed
What would you like to do?
Ruby inner method visibility bug
def foo
def bar
end
end
foo
p Object.instance_methods(false)
p Object.private_instance_methods(false)
# 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
# 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)
# 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
You can’t perform that action at this time.