class LoadPaths
# ...
def initialize
@paths = []
end
def push(*paths)
@paths.push(*paths)
end
def inspect
p @paths
end
end
a = LoadPaths.new
x = a.push(1)
x.push 2
a.inspect
There is no problem at all.
What tends to cause problems is this:
class A
def count
@count ||= 0
@count += 1
end
end
a = A.new
a.count # => 1
a.instance_variable_set(:@count, 10)
a.count # => 11
Among theminstance_variable_setyou can modify the instance variables within the object ~ ~
Of course, it can also be understood as the power of Ruby!!!
Instance methods operate instance variables, what’s the problem?
There is no problem at all.
What tends to cause problems is this:
Among them
instance_variable_set
you can modify the instance variables within the object ~ ~Of course, it can also be understood as the power of Ruby!!!