Project

General

Profile

Actions

Feature #8035

closed

singleton class should be included in ancestors

Added by marcandre (Marc-Andre Lafortune) almost 10 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:53171]

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 1 (0 open1 closed)

Related to Ruby master - Bug #8166: Since r39628 rspec-mock's and_call_original fail with SystemStackErrorRejectednagachika (Tomoyuki Chikanaga)03/27/2013Actions

Updated by alexeymuranov (Alexey Muranov) almost 10 years 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.

Updated by matz (Yukihiro Matsumoto) almost 10 years ago

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

Matz.

Actions #3

Updated by marcandre (Marc-Andre Lafortune) almost 10 years 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 (rb_mod_ancestors): 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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0