On 24 May 2013 16:20, Love U Ruby <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1110051:
>> On 24 May 2013 14:56, Love U Ruby <li...@ruby-forum.com> wrote:
>>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> b = a + [nil]
>>> p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> p b #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, nil]
>>>
>>> Is there any other Rubyist way to get the `b` array from `a` array?
>>
>> If what you really want is to add a nil element to a then you can just
>> do
>> a << nil
>> or, as Walter suggested
>> a.push nil
>>
>> Colin
>
> @Colin - I don't want to modify the array `a`. Thus `push` and `<<`
> can't be helpful. :)

OK, I thought it was worth checking.  Often people do not ask the
question that they should.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuDmqRYxTcu9cAZUAysW%3DU-RmAzueLHZxamdKTqutqcrw%40mail.gmail.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to