Directly accessing an instance variable vs. Using an accessor method

后端 未结 2 1543
北恋
北恋 2020-12-12 13:13

Can anyone explain the difference between accessing an instance attribute via self.attribute and by @attribute?

2条回答
  •  旧时难觅i
    2020-12-12 13:36

    "Accessing instance variable directly is about two times faster than accessing them with accessor methods"

    Check out the: https://www.greyblake.com/blog/2012-09-01-ruby-perfomance-tricks/

提交回复
热议问题