[#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:106183] [Ruby master Feature#16035] Allow non-finalizable objects such as Integer, static Symbol etc in ObjectSpace::WeakMap
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-11-19 20:35:46 UTC
List:
ruby-core #106183
Issue #16035 has been updated by Eregon (Benoit Daloze).
We implemented this correctly in TruffleRuby.
It's a little bit tricky as then indeed some wrapper with custom equals() is needed for primitives:
https://github.com/oracle/truffleruby/commit/e839f3f5887bdd04b855e286e9f74443fbcccf53
That means the exact same semantics as `equal?` on CRuby.
----------------------------------------
Feature #16035: Allow non-finalizable objects such as Integer, static Symbol etc in ObjectSpace::WeakMap
https://bugs.ruby-lang.org/issues/16035#change-94791
* Author: byroot (Jean Boussier)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
----------------------------------------
This goes one step farther than what @nobu did in https://bugs.ruby-lang.org/issues/13498
With this patch, special objects such as static symbols, integers, etc can be used as either key or values inside WeakMap. They simply don't have a finalizer defined on them.
This is useful if you need to deduplicate value objects, e.g. some minimal use case:
```ruby
class Money
REGISTRY = ObjectSpace::WeakMap.new
private_constant :REGISTRY
def self.new(amount)
REGISTRY[amount] ||= super.freeze
end
def initialize(amount)
@amount = amount
end
end
if Money.new(42).eql?(Money.new(42))
puts "Same instance"
else
puts "Different instances"
end
```
This is a very simple example, but more complex examples can create use a dynamically created symbol as deduplication key, etc.
It also removes one weirdness introduced in the mentioned patch:
```ruby
wmap = ObjectSpace::WeakMap.new
wmap["foo".to_sym] = Object.new # works fine with dynamic symbols
wmap[:bar] = Object.new # cannot define finalizer for Symbol (ArgumentError)
```
Proposed patch: https://github.com/ruby/ruby/pull/2313
--
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>