Issue #14097 has been updated by ana06 (Ana Maria Martinez Gomez).


I would that the difference is that there are some method where is not expected that the Array is modified, and some others where you expect it. So, for example, with `pop` and `push` I don't think we should have two methods, one which modify the object and another one which does it, but at least I would keep the Array operators methods consistent.

@jeremyevans0 do you find it coherent having you union method and only one concat? Won't be that confusing? you will always need to check the documentation as you won't know when the object is modified and when not. 

Also, `union` is an operation with Arrays when you when to use then as set for any reason. The main difference is that in the Array the order of the elements matter, so that is unrelated to the `Set` class.

----------------------------------------
Bug #14097: Add union and difference to Array
https://bugs.ruby-lang.org/issues/14097#change-67789

* Author: ana06 (Ana Maria Martinez Gomez)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Currently there is a concat method in ruby which does the same as +, but modifying the object. We could introduce a union and difference methods, which would be the equivalent for the `|` and `-` operators. This operators are normally less used due to lack of readability and expressivity. You end seeing thinks like:

```
array.concat(array2).uniq!
```

just because it is more readable. When it could be written like:

```
array |= array2
```

But, as this is not clear for some people, the new method will solve this problem:

```
array.union(array2)
```

And now this is clean and readable, as everybody expect from Ruby, the language focused on simplicity and productivity. ;)


Can I send a PR? :)





-- 
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>