ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "fxn (Xavier Noria) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "fxn (Xavier Noria)" <noreply@ruby-lang.org>
Subject: [ruby-core:112285] [Ruby master Feature#17753] Add Module#namespace
Date: Wed, 08 Feb 2023 10:01:57 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-101717.20230208100156.73@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17753.20210326191942.73@ruby-lang.org

Issue #17753 has been updated by fxn (Xavier Noria).


Let me reword that last remark about "the Ruby model suffers just a little bit".

Ruby objects and variables behave the same. But constants are not as orthogonal and generic:

1. When you assign an integer to a constant, it's just storage. If you assign a class or module object with a name, it's just storage. However, assigning an anonymous class or module object changes the state, it has a side-effect that is only programmed for these objects.
2. The `class` and `module` keywords perform constant assignments.

So, "suffer" is not an exact word for what I have in mind. I'd say this change would accentuate an already existing asimmetry, and in a way that is consitent with `Module#name`. This is not bad, it goes in a consistent direction.

----------------------------------------
Feature #17753: Add Module#namespace
https://bugs.ruby-lang.org/issues/17753#change-101717

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Priority: Normal
----------------------------------------
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.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:

```ruby
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](https://github.com/ruby/ruby/pull/4326).

---Files--------------------------------
0001-Add-Module-outer_scope.patch (5.93 KB)
0001-Add-Module-namespace.patch (5.89 KB)


-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2023-02-08 10:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 19:19 [ruby-core:103044] [Ruby master Feature#17753] Add Module#outer_scope tenderlove
2021-03-27  7:58 ` [ruby-core:103053] " sawadatsuyoshi
2021-03-27 11:33 ` [ruby-core:103057] " eregontp
2021-03-27 21:51 ` [ruby-core:103065] " tenderlove
2021-03-28  6:05 ` [ruby-core:103069] " sawadatsuyoshi
2021-03-28 13:33 ` [ruby-core:103072] " jean.boussier
2021-04-10 10:35 ` [ruby-core:103371] [Ruby master Feature#17753] Add Module#namespace fxn
2021-04-10 10:54 ` [ruby-core:103372] " fxn
2021-04-10 20:45 ` [ruby-core:103382] " fxn
2021-04-12 15:28 ` [ruby-core:103405] " tenderlove
2021-04-12 17:29 ` [ruby-core:103409] " eregontp
2021-04-13  9:29 ` [ruby-core:103417] " fxn
2021-04-13  9:37 ` [ruby-core:103418] " fxn
2021-04-13  9:46 ` [ruby-core:103419] " fxn
2021-04-13 10:01 ` [ruby-core:103420] " fxn
2021-04-13 10:57 ` [ruby-core:103422] " eregontp
2021-04-13 11:50 ` [ruby-core:103424] " fxn
2021-04-13 16:35 ` [ruby-core:103433] " fxn
2021-04-17  7:27 ` [ruby-core:103493] " mame
2021-04-17  8:04 ` [ruby-core:103496] " fxn
2022-07-01  6:52 ` [ruby-core:109108] " ioquatix (Samuel Williams)
2022-07-01 16:13 ` [ruby-core:109111] " sawa (Tsuyoshi Sawada)
2022-07-02  0:03 ` [ruby-core:109112] " ioquatix (Samuel Williams)
2022-07-02  5:01 ` [ruby-core:109114] " sawa (Tsuyoshi Sawada)
2022-07-03 23:41 ` [ruby-core:109129] " ioquatix (Samuel Williams)
2022-07-04  1:42 ` [ruby-core:109131] " austin (Austin Ziegler)
2023-02-08  3:41 ` [ruby-core:112273] " shioyama (Chris Salzberg) via ruby-core
2023-02-08  7:54 ` [ruby-core:112277] " fxn (Xavier Noria) via ruby-core
2023-02-08 10:01 ` fxn (Xavier Noria) via ruby-core [this message]
2023-02-09  8:02 ` [ruby-core:112295] " shioyama (Chris Salzberg) via ruby-core
2023-02-10  0:48 ` [ruby-core:112316] " shioyama (Chris Salzberg) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-101717.20230208100156.73@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).