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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -