Project

General

Profile

Actions

Feature #8035

closed

singleton class should be included in ancestors

Added by marcandre (Marc-Andre Lafortune) over 11 years ago. Updated over 11 years ago.

Status:
Closed
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) over 11 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) over 11 years ago

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

Matz.

Actions #3

Updated by marcandre (Marc-Andre Lafortune) over 11 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