Hey, thank you for reading this post. Why won''t this work? outer = [] func = ->(n) { outer << n } func[1] => outer stays empty. Why that? Since outer is readable in the lambda function it should be changeable as it is the same instance of the array. I am a bit confused. Thanks you very much for your answers. ms -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Are you doing this in the model, and is outer a member variable? If so, did you forget to use self on it? self.outer = [] func = lambda { |n| self.outer << n } func[1] On Friday, April 20, 2012 12:37:14 PM UTC-10, ms wrote:> > Hey, > > thank you for reading this post. > > Why won''t this work? > > outer = [] > func = ->(n) { outer << n } > func[1] > > => outer stays empty. Why that? Since outer is readable in the lambda > function it should be changeable as it is the same instance of the > array. I am a bit confused. > > Thanks you very much for your answers. > ms >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xdVC_59NzqgJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Oh, here''s with the new notation you''re using. Sorry about that. self.outer = [] func = -> n { self.outer << n } func[1] On Friday, April 20, 2012 2:32:08 PM UTC-10, IAmNan wrote:> > Are you doing this in the model, and is outer a member variable? If so, > did you forget to use self on it? > > self.outer = [] > func = lambda { |n| self.outer << n } > func[1] > > > On Friday, April 20, 2012 12:37:14 PM UTC-10, ms wrote: >> >> Hey, >> >> thank you for reading this post. >> >> Why won''t this work? >> >> outer = [] >> func = ->(n) { outer << n } >> func[1] >> >> => outer stays empty. Why that? Since outer is readable in the lambda >> function it should be changeable as it is the same instance of the >> array. I am a bit confused. >> >> Thanks you very much for your answers. >> ms >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KcMHZhKpcpQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you very much for your answer. I did not mention that I am not using Rails in this case. But the problem disappeared this morning - somehow. :) On 21 Apr., 02:35, IAmNan <dger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh, here''s with the new notation you''re using. Sorry about that. > > self.outer = [] > func = -> n { self.outer << n } > func[1] > > > > > > > > On Friday, April 20, 2012 2:32:08 PM UTC-10, IAmNan wrote: > > > Are you doing this in the model, and is outer a member variable? If so, > > did you forget to use self on it? > > > self.outer = [] > > func = lambda { |n| self.outer << n } > > func[1] > > > On Friday, April 20, 2012 12:37:14 PM UTC-10, ms wrote: > > >> Hey, > > >> thank you for reading this post. > > >> Why won''t this work? > > >> outer = [] > >> func = ->(n) { outer << n } > >> func[1] > > >> => outer stays empty. Why that? Since outer is readable in the lambda > >> function it should be changeable as it is the same instance of the > >> array. I am a bit confused. > > >> Thanks you very much for your answers. > >> ms-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.