Just curious what the best practice is for accessing an instance variable from within a class assuming attr_accessor is set.
class Test
attr_accessor :user
def initializer(user)
@user = user
end
def foo
@user
end
end
or
class Test
attr_accessor :user
def initializer(user)
@user = user
end
def foo
self.user
end
end
So by instance variable (@user) or getter method (Test#user)?
Getter method, because it’s easier to refactor. Say you want to update a time stamp at the point of access.
And all your references to
userare updated with the new logic. Not so easy if your references are to@user.