Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created June 22, 2012 16:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davidbalbert/2973857 to your computer and use it in GitHub Desktop.
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