I want to pass instance variables to a method, which then modifies them. This is because I have the same logic for different instance variables. Is this possible? I haven't got it working.
class A
def update_ivar()
update(@ivar)
end
def update(var)
var = 1
end
def print_ivar()
puts @ivar
puts @ivar == nil
end
end
a = A.new
a.update_ivar()
a.print_ivar()
Output
true
Array, aHash, or a similar container structure. You could do the same with instance variables, passing their name and looking them up using introspection, but that is an anti-pattern (less readable, less safe, and probably also less fast).