How to merge two arays in ruby
arrays, ruby, ruby-on-rails-3
Solution
I'm not at my computer to confirm this, but I think you can use:
a | b
Which creates the union of the two arrays.
See http://ruby-doc.org/core-2.0/Array.html#method-i-7C for the documentation.
Problem
I have two arrays.. ``` a = [1, 2, 3] b = [2, 3, 4] ``` I want to merge these two arrays in such a way that result should look like this. ``` [1, 2, 3, 4] ``` One way is to add these two arrays and the call `uniq!` method. ``` c = a + b c.uniq! ``` is there any shortcut method that I can do this in single call?