In general what is the best practice and pro/cons to creating an instance variable that can be accessed from multiple methods or creating an instance variable that is simply passed as an argument to those methods. Functionally they are equivalent since the methods are still able to do the work using the variable. While I could see a benefit if you were updating the variable and wanted to return the updated value but in my specific case the variable is never updated only read by each method to decide how to operate.
Example code to be clear:
class Test
@foo = "something"
def self.a
if @foo == "something"
puts "do #{@foo}"
end
end
a()
end
vs
class Test
foo = "something"
def self.a(foo)
if foo == "something"
puts "do #{foo}"
end
end
a(foo)
end
@foo = "something"at the class level will make it an instance variable of the class object, and not the test object. That was a gotcha for me, at least.@fooandfooare most likely NOT what you want.@@foowould be more appropriate.