[#99115] [Ruby master Bug#17023] How to prevent String memory to be relocated in ruby-ffi — larskanis@...
Issue #17023 has been reported by larskanis (Lars Kanis).
22 messages
2020/07/10
[#99375] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings — merch-redmine@...
Issue #17055 has been reported by jeremyevans0 (Jeremy Evans).
29 messages
2020/07/28
[#101207] [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings
— merch-redmine@...
2020/12/02
Issue #17055 has been updated by jeremyevans0 (Jeremy Evans).
[#101231] Re: [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings
— Austin Ziegler <halostatue@...>
2020/12/03
What does this mean?
[ruby-core:99112] [Ruby master Feature#16739] Allow Hash#keys and Hash#values to accept a block for filtering output
From:
jacobevelyn@...
Date:
2020-07-10 16:09:49 UTC
List:
ruby-core #99112
Issue #16739 has been updated by jacobevelyn (Jacob Evelyn).
sawa (Tsuyoshi Sawada) wrote in #note-5:
> Includes a duplicate of #14788.
I just want to note that this is a *more powerful* feature than what's proposed in #14788, because both the key and value would be available to the block.
Eregon (Benoit Daloze) wrote in #note-4:
> In general I think we avoid adding blocks to core methods, because indeed it's not clear if people expect #map, #select or #filter_map behavior, and it's so much clearer with the explicit call.
That's fair! Would calling these methods `filter_keys`/`filter_values` or `select_keys`/`select_values` be more explicit?
----------------------------------------
Feature #16739: Allow Hash#keys and Hash#values to accept a block for filtering output
https://bugs.ruby-lang.org/issues/16739#change-86487
* Author: jacobevelyn (Jacob Evelyn)
* Status: Open
* Priority: Normal
----------------------------------------
I often see code like the following:
``` ruby
hash.select { |_, v| v == :some_value }.keys
hash.keys.select { |k| k.nil? || k.even? }
hash.select { |k, v| valid_key?(k) && valid_value?(v) }.values
```
Each of these code snippets must allocate an intermediate data structure. I propose allowing `Hash#keys` and `Hash#values` to accept optional block parameters that *take both key and value*. For example, the above code could be rewritten as:
```ruby
hash.keys { |_, v| v == :some_value }
hash.keys { |k, _| k.nil? || k.even? }
hash.values { |k, v| valid_key?(k) && valid_value?(v) }
```
This behavior:
1. Does not break any existing code (since `Hash#keys` and `Hash#values` do not currently accept blocks).
2. Is very readable—it's obvious what it does at a glance.
3. Is more efficient than current alternatives.
4. Is more concise than current alternatives.
5. Is flexible and useful in a variety of scenarios, because the block has access to both key and value (unlike the behavior proposed in #14788).
--
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>