Use getter methods instead of instance variables in Ruby objects
02-May-2025 13
When I think about a Ruby object I try to minimize the public methods that it exposes. My line of thinking is that all methods should be private unless there is a real reason to make that method public.
When making a method public you are signing a contract with another developer that you will keep that method the same for as long as possible (the same parameters, the same return, the same effects …). So I think the default position should be to limit your liabilities.
A getter is a method so when you think about defining getters you should think if you really need to expose them and make them public.
Use getter methods instead of instance variables in Ruby objects #ruby #rubydeveloper #rubyonrails #getter #methods #instead #instance #variables #objects https://www.rubyonrails.ba/link/use-getter-methods-instead-of-instance-variables-in-ruby-objects