Skip to content

Conversation

tenderlove
Copy link
Member

@tenderlove tenderlove commented Mar 26, 2021

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

Redmine issue here

Given code like this:

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

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

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

```ruby
ObjectSpace.each_object(Class) do |k|
  p siblings: k.namespace.constants
end
```
@ko1
Copy link
Contributor

ko1 commented Nov 9, 2021

The discussion seems stayed and naming is not accepted. Do you want to keep this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants