Provide value for self when using Proc#call

后端 未结 3 580
既然无缘
既然无缘 2021-02-04 01:05

When using Proc#call to call a lambda function in Ruby, self always ends up with the value that it had when the function was defined, rather than the value it has w

3条回答
  •  梦毁少年i
    2021-02-04 01:53

    lambda defines a closure which means it will encapsulate the environment it had when it was defined. If you want self to be the caller just define a regular method or better yet use a block.

提交回复
热议问题