Why won't this lambda thing work?

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

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]

Oh, here’s with the new notation you’re using. Sorry about that.

self.outer =

func = → n { self.outer << n }

func[1]

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. :slight_smile: