ruby - Access variable inside block -
i'm using block in rubymotion , trying access instance variables inside of declared outside. turns out can't access variable inside. there obvious solution i'm missing here? thanks!
here code
@my_var = true dispatch::queue.concurrent.async # can't access @my_var here end
my guess async
runs block instance_eval
, instance variable binding other object when used inside block. if need read variable, use local copy inside block
@my_var = true my_var = @my_var dispatch::queue.concurrent.async my_var end
or if have accessor method
@my_var = true = self dispatch::queue.concurrent.async this.my_var end
Comments
Post a Comment