[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:106181] [Ruby master Feature#14332] Module.used_refinements to list refinement modules
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-11-19 20:23:42 UTC
List:
ruby-core #106181
Issue #14332 has been updated by Eregon (Benoit Daloze).
For Module.used_refinements, I believe it has to be an Array, not a Hash.
We can see in the description:
```ruby
p Module.used_refinements # => [#<refinement:Integer@Fact>, #<refinement:Integer@Json>, #<refinement:String@Json>]
```
The refined classes are not unique, so we can't key by refined class.
And the order matters, so a `Hash[namespace => [refined classes]]` would be bad and needlessly complicated.
Since the spec of `Module.used_refinements` seems clear, I suggest to add it soon.
----------------------------------------
Feature #14332: Module.used_refinements to list refinement modules
https://bugs.ruby-lang.org/issues/14332#change-94789
* Author: Eregon (Benoit Daloze)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Module.used_modules was added in #7418.
But I think `Module.used_refinements` is more useful or at least complementary.
Refinements were implemented in TruffleRuby, and I found Module.used_refinements so useful that I left it there.
Instead of listing namespace modules (arguments to #using), it lists the refinement modules:
~~~ ruby
module Json
refine Integer do
def to_json
to_s
end
end
refine String do
def to_json
inspect
end
end
end
module Fact
refine Integer do
def fact
self <= 1 ? 1 : self * (self-1).fact
end
end
end
using Json
p Module.used_modules # => [Json]
p Module.used_refinements # => [#<refinement:Integer@Json>, #<refinement:String@Json>]
using Fact
p Module.used_modules # => [Json, Fact]
p Module.used_refinements # => [#<refinement:Integer@Fact>, #<refinement:Integer@Json>, #<refinement:String@Json>]
~~~
This shows which classes are refined and by which refinement namespace.
It also shows if a class has multiple active refinements in the scope.
And, last but not least, the name of the method contains "refinements".
I find `used_modules` hard to remember and it doesn't sound related to refinements from the name (while looking at the Module's methods).
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>