Project

General

Profile

Actions

Feature #17753

open

Add Module#namespace

Added by tenderlovemaking (Aaron Patterson) over 3 years ago. Updated almost 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:103044]

Description

Given code like this:

module A
  module B
    class C; end
    class D; end
  end
end

We can get from C to B like C.outer_scope, or to A like
C.outer_scope.outer_scope.

I want to use this in cases where I don't know the outer scope, but I
want to find constants that are "siblings" of a constant. For example,
I can do A::B::C.outer_scope.constants to find the list of "sibling"
constants to C. I want to use this feature when walking objects and
introspecting. For example:

ObjectSpace.each_object(Class) do |k|
  p siblings: k.outer_scope.constants
end

I've attached a patch that implements this feature, and there is a pull request on GitHub here.


Files

0001-Add-Module-outer_scope.patch (5.93 KB) 0001-Add-Module-outer_scope.patch tenderlovemaking (Aaron Patterson), 03/26/2021 07:19 PM
0001-Add-Module-namespace.patch (5.89 KB) 0001-Add-Module-namespace.patch tenderlovemaking (Aaron Patterson), 03/27/2021 09:51 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0