This document explores a debate within the Ruby programming community regarding the preferred way to access data within classes, specifically focusing on instance variables versus getter methods. While some argue that getter methods are safer because they raise an error for undefined access, the author favors direct instance variable access for its visual clarity and immediate indication of raw data without side effects. To address the safety concern of accessing undefined instance variables, the author introduces a new tool called Strict Ivars. This tool acts as a Ruby pre-processor to add checks that will raise a NameError when an undefined instance variable is accessed, providing the safety benefits of getter methods while retaining the visual advantages of direct access. The author highlights the experimental nature of Strict Ivars and encourages feedback.
Links:
joel.drapper.me/ivars/
Official Resources:
www.ruby-lang.org/
ruby-doc.org/
rubyonrails.org/
コメント