If a method name ends in an equals sign (=), as in family_name= : Reserved words « Language Basics « Ruby






If a method name ends in an equals sign (=), as in family_name=


the method is a "setter," 

class Name
  def family_name=( family )
    @family_name = family
  end
  def given_name=( given )
    @given_name = given
  end
end

n = Name.new
n.family_name= "Matsumoto" # => "Matsumoto"
n.given_name= "Yukihiro" # => "Yukihiro"
p n # => <Name:0x1d441c @family_name="Matsumoto", @given_name="Yukihiro">

 








Related examples in the same category

1.Ruby's reserved words
2.If a method name ends with a question mark (?), as in eql?, then the method returns a Boolean
3.If a method name ends in an exclamation point (!), as in delete!
4.Classes and modules begin with an upper case letter.