Ruby instance variable access -



Ruby instance variable access -

just curious best practice accessing instance variable within class assuming attr_accessor 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 instance variable (@user) or getter method (test#user)?

getter method, because it's easier refactor. want update time stamp @ point of access.

class test def user @user.last_read = time.now @user end end

and references user updated new logic. not easy if references @user.

ruby

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -