Search code examples
ruby-on-railsrubyresqueattr-accessor

Ruby Resque , @queue instance varaible


I am a newbie and just started learning ruby. I find Resque amazing but am faced with a question when reading the documentation.

We define a @queue instance variable inside a job class without defining any attr_reader, so how can a worker find the value of this instance variable later?


Solution

  • Ruby does not provide true isolation of instance variables- it is more of a recommendation. So private instance variables of an object can actually be accessed by other objects through multiple means like instance_variable_get, instance_eval etc.

    Resque uses instance_variable_get to extract the queue name from instance variable.

    The relevant source is here.