0
0

Ruby extendについて

Posted at

はじめに

※以下の内容には誤りが含まれる可能性があります

extendとは何か

extendとはモジュールのメソッドを使用するためのメソッドです。

クラスの中でモジュールを呼び出すときに使います。

その際extendはクラスメソッドとして読み込む。

extendの使い方

module cat
def name
 "ミケ"
  end
 end

 class Animal
  extend Cat
end

p Animal.name

includeメソッドとの違いはクラスメソッドとしてモジュールがインクルードされる点です。

まとめ

  • extendはモジュールを使用するためのメソッド
  • extendeはクラスメソッドとして読み込む
0
0
0

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