[ruby-core:94357] [Ruby master Feature#16104] Introduce merge_if and merge_if!
From:
shevegen@...
Date:
2019-08-14 20:51:38 UTC
List:
ruby-core #94357
Issue #16104 has been updated by shevegen (Robert A. Heiler).
Hmmm. I have mixed feelings about it. I think being able to add something
into e. g. a Hash, based on a conditional inside of the method, may be useful.
We also have at the least one example of "_if", such as for Array:
.delete_if
Where (I think) this may be equal to Array#reject!.
There is no .delete_if! though, so perhaps this may apply to your feature
request too.
On the other hand ... visually I am not entirely sure whether this is
quite elegant, although this is highly subjective.
Consider:
if foobar
barfoo.merge_if(b: 'Ball') {|k, v| v == 'Apple'}
end unless blub
This is of course contrived, but the part I am unsure is whether we should
have more **NAME_if** methods as such. I can not say whether I am completely
against it, but I am a bit wary of such method names that include conditionals
in the name itself.
I think most ruby names tend to be one word; a few are two words.
(If anyone knows of more methods that have "_if" as part of their names,
in core/stdlib, please feel free to add to the list - I really do not know
of more examples off the top of my head.)
PS: On a side note, I never manage to remember the difference between .merge()
.merge!() and .update() off-hand - I always try in irb first; I only know one
is an alias ... :D
----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104#change-80763
* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.
--
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>