Method names-how to indicate get vs set type of method?


#1

hi,

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

tks


#2

On Nov 5, 9:07 pm, “Greg H.” removed_email_address@domain.invalid
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