[#112457] [Ruby master Feature#19443] Cache `Process.pid` — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #19443 has been reported by byroot (Jean Boussier).
16 messages
2023/02/16
[#112584] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system — "normalperson (Eric Wong) via ruby-core" <ruby-core@...>
Issue #19465 has been reported by normalperson (Eric Wong).
9 messages
2023/02/25
[#112595] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— "nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
2023/02/25
SXNzdWUgIzE5NDY1IGhhcyBiZWVuIHVwZGF0ZWQgYnkgbm9idSAoTm9idXlvc2hpIE5ha2FkYSku
[#112613] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/26
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@ml.ruby-lang.org> wrote:
[#112615] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— SHIBATA Hiroshi via ruby-core <ruby-core@...>
2023/02/27
MzUxMzZlMWU5YzIzMmFkN2EwMzQwN2I5OTJiMmU4NmI2ZGY0M2Y2MyBpcyBicm9rZW4gd2l0aCBg
[#112626] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/28
```
[ruby-core:112605] [Ruby master Feature#19450] Is there an official way to set a class name without setting a constant?
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-02-25 12:41:13 UTC
List:
ruby-core #112605
Issue #19450 has been updated by Eregon (Benoit Daloze).
ioquatix (Samuel Williams) wrote in #note-18:
> > One requirement for that is the given name should not be a valid constant name then (not start with a uppercase letter).
>
> That's not how it works internally, there is actually a flag for anonymous/permanent name.
It's a requirement for humans to always be able to tell the difference. That flag is not exposed or shown.
> I wondered about whether your point of class name consistent was valid, but I found cases like this:
Yes, as I already mentioned in https://github.com/ruby/ruby/pull/7376#issuecomment-1445057920.
But `remove_const` or overriding a constant is very rarely used, there is a reason they are private or warn.
And in practice they aren't used much, so (the original) `Module#name` does reflect in 99+% how to access a named module, and that is valuable.
This feature hurts that, and `Module#name` is now possibly a "random user-supplied value" or worse a "looks like a constant path but is fake and was never assigned" (the latter one can be addressed by the requirement above).
---
I don't get why you want to show the file path in Module#name, this information is already available in the backtrace and in fact is more precise in the backtrace:
```
Module.new do
self::C = Class.new
c = self::C.new
c.foo
end
---
t.rb:4:in `block in <main>': undefined method `foo' for #<#<Module:0x00007f735567e880>::C:0x00007f73673fa1b0> (NoMethodError)
c.foo
^^^^
from t.rb:1:in `initialize'
from t.rb:1:in `new'
from t.rb:1:in `<main>'
```
How is `#<t.rb::C:0x00007f73673fa1b0>` more useful? (it might look better to you, but what is the actual usefulness of it?)
The relevant information here is `t.rb:4` which is already there.
I have the feeling you hate the notation `#<#<Module:0x1234>::C:0x5678>`, which yes that's a bit cryptic, but it's missing the point this is hardly relevant in an exception such as the one above.
For the example in https://bugs.ruby-lang.org/issues/19450#note-6 you can just define `inspect` as an instance method of that class and be done with it.
You can customize `inspect` on the class itself like Rails does if you think people will do a lot of `p self.class` in `sus` or so.
In other words, a module name and a file path are separate things.
----------------------------------------
Feature #19450: Is there an official way to set a class name without setting a constant?
https://bugs.ruby-lang.org/issues/19450#change-102052
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
This is the best I could come up with:
```ruby
klass = Class.new
Object.const_set("Klass", klass)
Object.send(:remove_const, "Klass")
puts klass.new
# => #<Klass:0x0000000100a9d688>
```
Can we do better?
What about something like:
```ruby
Class.new(name: "Klass")
```
or
```ruby
Class.new do
def self.name
"Klass"
end
end
```
etc
--
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/