Forum: Ruby method names-how to indicate get vs set type of method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-11-06 04:09
(Received via mailing list)
hi,

What is the naming convention for method names to clarify whether its
a get or set type of method?

tks
B1b1d33e0655e841d4fd8467359c58d0?d=identicon&s=25 Yossef Mendelssohn (Guest)
on 2008-11-06 04:21
(Received via mailing list)
On Nov 5, 9:07 pm, "Greg Hauptmann" <greg.hauptmann.r...@gmail.com>
wrote:
> What is the naming convention for method names to clarify whether its
> a get or set type of method?

Ruby methods can end in =, so that's a good choice.

  class Square
    def height
      @height
    end

    def height=(val)
      @height = val
    end
  end

Note that you can do the same in a much easier way.

  class Square
    attr_accessor :height
  end
This topic is locked and can not be replied to.