[#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:112603] [Ruby master Feature#19450] Is there an official way to set a class name without setting a constant?
From:
"ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>
Date:
2023-02-25 12:02:30 UTC
List:
ruby-core #112603
Issue #19450 has been updated by ioquatix (Samuel Williams).
Here are some of the places in my own code I'd like to use such a feature:
- https://github.com/ioquatix/bake/blob/a571f0c47cc202a4b46a836b87b7383d84f74fa0/lib/bake/scope.rb#L30 - "Scope<path/to/file.rb>"
- https://github.com/ioquatix/bake/blob/a571f0c47cc202a4b46a836b87b7383d84f74fa0/lib/bake/base.rb#L32 - "<Path/To/File>" probably makes sense.
- https://github.com/socketry/utopia/blob/7f24d503f46000076fbdeeb6e28e293c9544b37b/lib/utopia/controller.rb#LL65C29-L65C29 - probably "Controller<relative/uri/path>"
- https://github.com/ioquatix/sus/blob/65e408bad260d168701bad79b2cb905ef65435e8/lib/sus/base.rb#L43 - probably "Base<description>"
- https://github.com/ioquatix/sus/blob/65e408bad260d168701bad79b2cb905ef65435e8/lib/sus/it.rb#L11 - probably "It<path/to/file.rb:line>"
There are other systems that would benefit from this, e.g. RSpec, or any test framework which loads tests into anonymous modules, or any system that basically creates `Module.new`/`Class.new` and subsequently loads code from one or more files into them.
> But it doesn't affect Module#name and error messages, which IMO is good, so error messages don't lie about this.
I disagree, the anonymous `#<#<Class:0x00007fd0ad4b3860>::Bar:0x00007fd0ad81ec70>` names are near useless. Where did it come from? Where was it defined?
> Related, Marshal and other places use rb_mod_name() (or similar) to find the class name.
In my PR, it's still considered an anonymous class. So it can't be marshalled.
> 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.
----------------------------------------
Feature #19450: Is there an official way to set a class name without setting a constant?
https://bugs.ruby-lang.org/issues/19450#change-102050
* 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/