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? -- Posted via http://www.ruby-forum.com/. -- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2da174969111a227ea087d4b8798a1a3%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
b = a.push nil Walter On May 24, 2013, at 9:56 AM, Love U Ruby 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? > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2da174969111a227ea087d4b8798a1a3%40ruby-forum.com?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/04B8F6E4-96C9-4101-96A3-6F239B074F87%40wdstudio.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Oh, duh, never mind, that pushes it onto a also. Walter On May 24, 2013, at 9:56 AM, Love U Ruby 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? > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2da174969111a227ea087d4b8798a1a3%40ruby-forum.com?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1B9E4B82-EF95-47B4-91D5-FB3BBE391949%40wdstudio.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
On 24 May 2013 14:56, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 -- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtDL0AnszQaE4KRkOtjoDXHEgt5cUKgQW3SyjsP9G5iGw%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Okay, this works: 1.9.3-p392 :009 > a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 1.9.3-p392 :010 > b = [a, nil].flatten => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, nil] 1.9.3-p392 :011 > b => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, nil] 1.9.3-p392 :012 > a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] On May 24, 2013, at 10:00 AM, Walter Lee Davis wrote:> b = a.push nil > > Walter > > On May 24, 2013, at 9:56 AM, Love U Ruby 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? >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> -- >> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2da174969111a227ea087d4b8798a1a3%40ruby-forum.com?hl=en-US. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > -- > 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/04B8F6E4-96C9-4101-96A3-6F239B074F87%40wdstudio.com?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/92379603-42DF-4CF2-A067-C503F69985CB%40wdstudio.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1110051:> On 24 May 2013 14:56, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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. :) -- Posted via http://www.ruby-forum.com/. -- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a290e32457644b077cc398ecd7751a28%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
a = [1,2,3,4,5,6,7,8,9,10] b= a.reverse.reverse On Friday, May 24, 2013 9:56:39 AM UTC-4, Ruby-Forum.com User 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? > > -- > Posted via http://www.ruby-forum.com/. >-- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a96218e0-0aa0-4fe3-b4c6-b8a76d197215%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
On 24 May 2013 16:20, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1110051: >> On 24 May 2013 14:56, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Fri, May 24, 2013 at 10:33 AM, Paul Julian <bpj101-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> a = [1,2,3,4,5,6,7,8,9,10] > b= a.reverse.reverseCan''t tell if you are trolling or if you think that''s actually a good idea. How about just doing: a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] b = a.dup> > On Friday, May 24, 2013 9:56:39 AM UTC-4, Ruby-Forum.com User 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?-- 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnx9wiM_odgT51wTmc-211tCLwpkK3NxFYAAg_Ao2cMxpQ%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.