Skip to content

Changing method visibility changes method ownership, but doesn't on MRI #2565

@myronmarston

Description

@myronmarston

I'm noticing that when you change method visibility on JRuby, it has a side effect that's not present on MRI: it changes what Method#owner returns.

First, here's the behavior on MRI 2.2:

➜  ~  ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin12.0]
➜  ~  ruby -e "class A; private_class_method :new; end; puts A.method(:new).owner"
Class
➜  ~  ruby -e "class A; private :inspect; end; puts A.instance_method(:inspect).owner"
Kernel

It looks like this has always been MRI's behavior; on 1.8.7 I see the same thing:

➜  ~  ruby -v
ruby 1.8.7 (2013-12-22 patchlevel 375) [i686-darwin12.5.0]
➜  ~  ruby -e "class A; private_class_method :new; end; puts A.method(:new).owner"
Class
➜  ~  ruby -e "class A; private :inspect; end; puts A.instance_method(:inspect).owner"
Kernel

Compare that to JRuby's behavior:

➜  ~  ruby -v
jruby 1.7.8 (1.9.3p392) 2013-11-14 0ce429e on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
➜  ~  ruby -e "class A; private_class_method :new; end; puts A.method(:new).owner"
#<Class:A>
➜  ~  ruby -e "class A; private :inspect; end; puts A.instance_method(:inspect).owner"
A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions