ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120174] [Ruby master Bug#20943] Constant defined in `Data` block
@ 2024-12-11  2:06 nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-11 10:29 ` [ruby-core:120176] [Ruby master Bug#20943] Constant defined in `Data.define` block byroot (Jean Boussier) via ruby-core
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-11  2:06 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20943 has been reported by nobu (Nobuyoshi Nakada).

----------------------------------------
Bug #20943: Constant defined in `Data` block
https://bugs.ruby-lang.org/issues/20943

* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
>From https://github.com/ruby/ruby/pull/12274:
> A couple times in code review I've seen constants inadvertently leak to top level from within a `Struct` or `Data` do block. I think it would be nice to show reopening the `Data` class when a constant is defined, so the constant is defined within the namespace. In this case, `Measure::NONE` instead of top level `Object::NONE`. It would also show readers that it's okay to reopen a `Data` class, which seems nice since some folk might not realize. Thanks for considering!

However, I think that `NONE` probably might be intended to be defined under `Measure`.

Current:
```ruby
Measure = Data.define(:amount, :unit) do
  NONE = Data.define
end
p NONE #=> NONE
```

Another:
```ruby
Measure = Data.define(:amount, :unit) do
  NONE = Data.define
  p NONE #=> Measure::NONE
end
p NONE # uninitialized constant NONE (NameError)
```

@zverok How do think?



-- 
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/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-12-30 10:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-11  2:06 [ruby-core:120174] [Ruby master Bug#20943] Constant defined in `Data` block nobu (Nobuyoshi Nakada) via ruby-core
2024-12-11 10:29 ` [ruby-core:120176] [Ruby master Bug#20943] Constant defined in `Data.define` block byroot (Jean Boussier) via ruby-core
2024-12-11 18:56 ` [ruby-core:120182] " matheusrich (Matheus Richard) via ruby-core
2024-12-17 23:51 ` [ruby-core:120284] " shan (Shannon Skipper) via ruby-core
2024-12-18  6:19 ` [ruby-core:120291] " matz (Yukihiro Matsumoto) via ruby-core
2024-12-18  7:58 ` [ruby-core:120293] " zverok (Victor Shepelev) via ruby-core
2024-12-24 20:16 ` [ruby-core:120400] " luke-gru (Luke Gruber) via ruby-core
2024-12-30 10:35 ` [ruby-core:120446] " byroot (Jean Boussier) via ruby-core

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 NNTP newsgroup(s).