0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Ruby】def hoge=(fuga) という書き方

Last updated at Posted at 2022-04-09

本題

Qiita や企業の技術ブログを見ていて,def hoge=(fuga) という書き方がありました.

class Author
    def authors_attributes=(attributes)
        @person_attributes = Person.new(attributes)
    end
end

hoge= で一つのメソッド名を表しています.
値の設定専用のメソッド(つまりセッター)ということを表すために,よく使われる書き方みたいです!知りませんでした!

呼び出すときは,以下のような書き方だけではなく,

Author.authors_attributes=(attribute)

以下のような書き方もできるみたいです.

Author.authors_attributes = attribute

参考記事

下の記事では,セッターの関数名にhoge= という書き方が使われています.

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?