[#71439] [Ruby trunk - Feature #11339] [PATCH] io.c: avoid kwarg parsing in C API — matz@...
Issue #11339 has been updated by Yukihiro Matsumoto.
7 messages
2015/11/11
[#71473] Re: [Ruby trunk - Feature #11339] [PATCH] io.c: avoid kwarg parsing in C API
— Eric Wong <normalperson@...>
2015/11/13
Entire series for sockets
[#71450] Ruby 2.3.0-preview1 Released — "NARUSE, Yui" <naruse@...>
Hi,
5 messages
2015/11/11
[#71617] [Ruby trunk - Feature #11664] [PATCH] introduce rb_autoload_value to replace rb_autoload — nobu@...
Issue #11664 has been updated by Nobuyoshi Nakada.
3 messages
2015/11/20
[#71721] [Ruby trunk - Feature #11741] Migrate Ruby to Git from Subversion — me@...
Issue #11741 has been updated by Jon Moss.
4 messages
2015/11/28
[ruby-core:71564] [Ruby trunk - Feature #11710] [PATCH] Replace Set#merge with Set#merge! and make Set#merge non-mutating.
From:
tieg.zaharia@...
Date:
2015-11-18 19:28:53 UTC
List:
ruby-core #71564
Issue #11710 has been updated by Tieg Zaharia.
File non_mutating_set_merge_method.2.diff added
(updating patch with a better change to the | method)
----------------------------------------
Feature #11710: [PATCH] Replace Set#merge with Set#merge! and make Set#merge non-mutating.
https://bugs.ruby-lang.org/issues/11710#change-54946
* Author: Tieg Zaharia
* Status: Open
* Priority: Normal
* Assignee: Akinori MUSHA
----------------------------------------
The Set#merge method currently mutates its caller. I propose changing its behavior to non-mutating, and replace its current behavior with a mutating Set#merge! method.
For example, the current behavior:
```
> s = Set.new [1,2,3] # => #<Set: {1, 2, 3}>
> s.object_id # => 70125370250380
> s.merge([4,5,6]) # => #<Set: {1, 2, 3, 4, 5, 6}>
> s # => #<Set: {1, 2, 3, 4, 5, 6}>
> s.object_id # => 70125370250380
```
Set describes itself as a hybrid of Array and Hash, but Hash#merge does not mutate its caller, and Set is implemented on top of Hash as well. Hash has a merge! method that can mutate instead:
```
> h = {a: 1, b: 2} # => {:a=>1, :b=>2}
> h.object_id # => 70125369896320
> h.merge({c: 3}) # => {:a=>1, :b=>2, :c=>3}
> h # => {:a=>1, :b=>2}
irb(main):015:0> h.object_id # => 70125369896320
```
We were taken by surprise with the existing behavior of Set#merge, especially since Set follows the bang pattern of mutating/non-mutating method names (e.g. collect!, reject!, select!, flatten!)
I noticed this has been [suggested before](https://bugs.ruby-lang.org/issues/5185), but was hoping it might be possible as a breaking change for 2.3.0?
---Files--------------------------------
non_mutating_set_merge_method.diff (1.47 KB)
non_mutating_set_merge_method.2.diff (1.47 KB)
--
https://bugs.ruby-lang.org/