Project

General

Profile

Actions

Feature #7876

closed

Add method for accessing Class from within Singleton Class

Feature #7876: Add method for accessing Class from within Singleton Class

Added by wardrop (Tom Wardrop) over 13 years ago. Updated 12 days ago.

Status:
Closed
Target version:
-
[ruby-core:52436]

Description

=begin
I'm quite surprised I haven't run into this sooner, but I seem to have just discovered that there's no means by which you can access the outer Class object once inside the context of the Singleton Class. Take the following example; how would I get a reference to (({Test})) from within the singleton?

class Test
class << self
# How do I get a reference to Test from here?
end
end

I assume the answer is that there is no reliable way, hence the reason for this request. Could we add a method to the singleton class that allows access to the "outer" class, e.g.

class Test
class << self
self.outerclass
end
end

Thoughts?
=end


Related issues 1 (0 open1 closed)

Related to Ruby - Feature #12084: `Class#instance`ClosedActions

Updated by ko1 (Koichi Sasada) over 13 years ago Actions #1 [ruby-core:52650]

  • Category set to core
  • Assignee set to matz (Yukihiro Matsumoto)
  • Target version set to 2.6

Updated by duerst (Martin Dürst) over 13 years ago Actions #2 [ruby-core:52670]

This should be possible with Module#ancestors. Maybe not totally slick, but possible.

Updated by naruse (Yui NARUSE) over 8 years ago Actions #3

  • Target version deleted (2.6)

Updated by hsbt (Hiroshi SHIBATA) over 2 years ago Actions #4

  • Status changed from Open to Assigned

Updated by Earlopain (Earlopain _) 12 days ago Actions #5

Updated by Earlopain (Earlopain _) 12 days ago Actions #6 [ruby-core:126076]

  • Status changed from Assigned to Closed

Implemented as attached_object in https://bugs.ruby-lang.org/issues/12084

class Test
  class << self
    p attached_object # => Test
  end
end
Actions

Also available in: PDF Atom