Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class does not inherit singleton_class's class methods #287

Closed
kachick opened this issue Sep 5, 2012 · 8 comments · Fixed by #5394
Closed

Class does not inherit singleton_class's class methods #287

kachick opened this issue Sep 5, 2012 · 8 comments · Fixed by #5394

Comments

@kachick
Copy link
Contributor

kachick commented Sep 5, 2012

I have faced a different behavior with MRI/YARV.
Is this expected?

set up

class Foo
  class << self
    class << self
      def foo; end
    end
  end
end

class Bar < Foo; end

Bar.singleton_class.foo

MRI/YARV

ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

Bar.singleton_class.foo #=> nil

JRuby

jruby 1.7.0.preview2 (1.9.3p203) 2012-09-03 b37a0bd on Java HotSpot(TM) Server VM 1.7.0_07-b10 [linux-i386]

Bar.singleton_class.foo #=> NoMethodError: undefined method `foo' for #<Class:Bar>
@the8472
Copy link
Contributor

the8472 commented Dec 10, 2012

I think I've run into a related issue, in my case with a module that gets included into another module that extends the a class's singleton class

see https://gist.github.com/4240807

@rjnienaber
Copy link

This still seems to be an issue in JRuby 1.7.20 and JRuby HEAD:

----------
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin14.0.0]
nil
----------
jruby 1.7.20 (1.9.3p551) 2015-05-04 3086e6a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_05-b13 +jit [darwin-x86_64]
NoMethodError: undefined method `foo' for #<Class:Bar>
  (root) at /tmp/test.rb:11
==========
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
nil
----------
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-05 c0d9bc3 Java HotSpot(TM) 64-Bit Server VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
NoMethodError: undefined method `foo' for #<Class:Bar>
  method_missing at org/jruby/RubyBasicObject.java:1606
           <top> at /tmp/test.rb:11
----------

eregon added a commit that referenced this issue Aug 22, 2016
ffdfa41 fix spec description
763e265 Fix double close in ARGF#read_nonblock spec
34d5bd1 Do not expect stdin to be the standard one in ARGF#read_nonblock
6a4a506 Remove stale comment
d23843f Merge pull request #289 from nobu/bug/fix-spawn
acf7634 ruby_cmd for spawn
6ef8ffc AppVeyor: run on every branch
705f41f windows guard fox unix sockets
ee7ff0e Do not guess a free port but use find_available_port
5258c31 Merge pull request #287 from etehtsea/add-inspec-sockaddr
4ee1776 Correctly pass interpreter arguments and flags in Process#kill specs
bb0c704 Remove most usages of RUBY_EXE and replace by ruby_cmd
22f9a5b Use ruby_cmd instead of RUBY_EXE in popen specs
1f85144 Fix a couple specs assuming RUBY_EXE is only a path without flags
ea5303a Share a few #spawn specs and use ruby_cmd over RUBY_EXE
721e379 Add Addrinfo#inspect_sockaddr spec
981a6e7 Windows seems to pack socket options in a short
0416004 join thread in ObjectSpace.each_object
e061bfe Add windows guard for lgamma
4864e06 Add a few windows guards
d2656bc Some environments seem to not fill the cannoname

git-subtree-dir: spec/ruby
git-subtree-split: ffdfa41f12ce35e1c91dab3a72b95edf4020b3ea
@rcrews
Copy link
Contributor

rcrews commented Feb 21, 2018

Just ran the above test case with 9.1.16.0. Can this be closed?

15:48:59 ~ 🐾  irb
jruby-9.1.16.0 :001 > class Foo
jruby-9.1.16.0 :002?>     class << self
jruby-9.1.16.0 :003?>         class << self
jruby-9.1.16.0 :004?>             def foo; end
jruby-9.1.16.0 :005?>           end
jruby-9.1.16.0 :006?>       end
jruby-9.1.16.0 :007?>   end
 => :foo 
jruby-9.1.16.0 :008 >   class Bar < Foo; end
 => nil 

@kares
Copy link
Member

kares commented Feb 22, 2018

closing - especially since it was reported against 1.7 which is EOL. thanks @rcrews

@kares kares closed this as completed Feb 22, 2018
@kares kares added this to the Invalid or Duplicate milestone Feb 22, 2018
@prashantvithani
Copy link
Contributor

@kares This issue still persists in 9.2.0.0

jruby-9.2.0.0 :015 > class Foo
jruby-9.2.0.0 :016?>     class << self
jruby-9.2.0.0 :017?>         class << self
jruby-9.2.0.0 :018?>             def foo; end
jruby-9.2.0.0 :019?>           end
jruby-9.2.0.0 :020?>       end
jruby-9.2.0.0 :021?>   end
 => :foo 
jruby-9.2.0.0 :022 > 
jruby-9.2.0.0 :023 > class Bar < Foo; end
 => nil 
jruby-9.2.0.0 :024 > Foo.singleton_class.foo
 => nil 
jruby-9.2.0.0 :025 > Bar.singleton_class.foo
Traceback (most recent call last):
        7: from /Users/prvithani/.rvm/rubies/jruby-9.2.0.0/bin/irb:13:in `<main>'
        6: from org/jruby/RubyKernel.java:1180:in `catch'
        5: from org/jruby/RubyKernel.java:1180:in `catch'
        4: from org/jruby/RubyKernel.java:1418:in `loop'
        3: from org/jruby/RubyKernel.java:1037:in `eval'
        2: from (irb):25:in `<eval>'
        1: from org/jruby/RubyBasicObject.java:1720:in `method_missing'
NoMethodError (undefined method `foo' for #<Class:Bar>)
jruby-9.2.0.0 :026 > 

@kares kares reopened this Aug 24, 2018
@lokeshdevnani
Copy link

@prashantvithani @kares Facing the same issue

@headius
Copy link
Member

headius commented Sep 19, 2018

This appears to be working in 9.2.1.0. I'm trying to confirm what commit fixed it.

@headius
Copy link
Member

headius commented Sep 19, 2018

Nevermind...I forgot the original script does not include the failing line. I'll edit it so we don't make the same mistake.

@kares kares self-assigned this Oct 30, 2018
kares added a commit to kares/jruby that referenced this issue Oct 31, 2018
... class of class' singleton class

an old issue that existed all the way back in JRuby 1.7 (jrubyGH-287)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants