From: Igor Pirnovar Date: 2013-04-01T03:19:12+09:00 Subject: Re: Private setters can be called by self, why not getters? You have to define setters and getters in ruby more carefully, when you intend to use them as private methods! You have to separate what is getter and what is setter, especially, when one and the same symbol can be used for both operations simultaneously as is the case in combined assignment operators such as +=, -=, *=, /= ... Here is how you manage the getters and setters when setter but not getter should be private: --------------------------------------------------- #!/usr/bin/env ruby class Counter attr_reader :count attr_writer :count private :count= def initialize; self.count = 0; end def show_count; puts "Count=#{count}"; end def increment1; self.count = count + 1; end def increment2; self.count = self.count + 1; end def increment3; self.count += 1; rescue; end end o = Counter.new o.show_count o.increment1 o.show_count #=> Count=0 o.increment2 o.show_count #=> Count=1 o.increment3 o.show_count #=> Count=2 puts "Explicit get: Count=#{o.count}" #=> Explicit get: Count=2 o.count=1234 ---------------------------------------------------- Indeed, if you do not care or are ignorant of oo, you can resort to devices like the underscore as suggested above. -- Posted via http://www.ruby-forum.com/.