LoginSignup
0
0

More than 5 years have passed since last update.

クラス、モジュールのメソッドを使う

Last updated at Posted at 2019-01-22

1.クラスを継承する

クラスを継承して、継承したクラスのメソッドを使う。
rubyは単一継承を採用しており、1つのクラスは、1つのスーパークラスしか持てない。

2.モジュールをincludeする

使用したいメソッドをまとめたモジュールをincludeして、そのモジュールのメソッドを使う。
継承と違い複数のモジュールをinclude出来るため、多重継承のような形でメソッドを使用出来る。(Mix-in)

3.モジュールをextendする

モジュールをincludeではなく、extendする。
includeと同じく、モジュールのメソッドが使用可能になるが、extendした場合はクラスメソッドとして使用可能となる。

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