Feature #8035

singleton class should be included in ancestors

Added by Marc-Andre Lafortune about 1 year ago. Updated about 1 year ago.

[ruby-core:53171]
Status:Closed
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:core
Target version:2.1.0

Description

I feel it would be consistent if:

k.ancestors.include?(k) #=> always true if k.is_a?(Class)

This is currently the case except for singleton classes:

class << ""; include Enumerable; end.ancestors
# => [Enumerable, String, Comparable, Object, Kernel, BasicObject]
# would be more consistent:
# => [#<Class:#<String:0x0000010113d268>>, Enumerable, String, Comparable, Object, Kernel, BasicObject]

Note that the singleton classes do appear in the ancestors if a module is instead prepended:

class << ""; prepend Enumerable; end.ancestors
# => [Enumerable, #<Class:#<String:0x0000010113d268>>, String, Comparable, Object, Kernel, BasicObject]

Thanks


Related issues

Related to ruby-trunk - Bug #8166: Since r39628 rspec-mock's and_call_original fail with Sys... Rejected 03/27/2013

Associated revisions

Revision 39628
Added by Marc-Andre Lafortune about 1 year ago

  • class.c (rbmodancestors): Include singleton_class in ancestors list
    [Feature #8035]

  • test/ruby/test_module.rb (class): test for above

  • test/ruby/marshaltestlib.rb (module): adapt test

  • NEWS: list change

Revision 40004
Added by Marc-Andre Lafortune about 1 year ago

  • NEWS: Be more precise about singleton_class.ancestors change [Feature #8035]

History

#1 Updated by Alexey Muranov about 1 year ago

Singleton class it the same thing as metaclass, right? I feel it would be better to keep it invisible, and maybe in the future to remove it completely and to allow objects to keep their singleton methods themselves.

#2 Updated by Yukihiro Matsumoto about 1 year ago

Agreed. I will accept it unless any other compatibility problem raises.

Matz.

#3 Updated by Marc-Andre Lafortune about 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39628.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • class.c (rbmodancestors): Include singleton_class in ancestors list
    [Feature #8035]

  • test/ruby/test_module.rb (class): test for above

  • test/ruby/marshaltestlib.rb (module): adapt test

  • NEWS: list change

Also available in: Atom PDF