As described earlier, method calls in Ruby usually involve a method lookup in a hash structure, which is considerably more expensive than a simple machine-supported subroutine call in statically compiled languages. We therefore want to avoid method calls as much as possible.
Accesses to class/module attributes declared via
attr_writer all involve method calls. We can reduce the overhead of attribute access by using the corresponding instance variables directly. So, instead of
attribute, we’d write
@attribute. And instead of
self.attribute = expr
@attribute = expr
which results in shorter code as well.
Obviously, this transformation breaks encapsulation and ...