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
msmsms
April 21, 2012, 2:33am
2
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]
msmsms
April 21, 2012, 2:36am
3
Oh, here’s with the new notation you’re using. Sorry about that.
self.outer = []
func = -> n { self.outer << n }
func[1]
msmsms
April 21, 2012, 1:18pm
4
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.