るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.275秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

検索結果

Module#include(*mod) -> self (18175.0)

モジュール mod をインクルードします。

...てしまうような include を行った場合に発生します。

//emlist[例][ruby]{
module M
end
module M2
include
M
end
module M
include
M2
end
//}

実行結果:

-:3:in `append_features': cyclic include detected (ArgumentError)
from -:3:in `include'
from -:3...
...
インクルードは多重継承の代わりに用いられており、 mix-in とも呼びます。

//emlist[例][ruby]{
class C
include
FileTest
include
Math
end

p C.ancestors

# => [C, Math, FileTest, Object, Kernel]
//}

モジュールの機能追加は、クラスの継承関係の...
...ッド探索の順序です)。

同じモジュールを二回以上 include すると二回目以降は無視されます。

//emlist[例][ruby]{
module M
end
class C1
include
M
end
class C2 < C1
include
M # この include は無視される
end

p C2.ancestors # => [C2, C1, M, Object, Ker...

Module#append_features(module_or_class) -> self (18139.0)

モジュール(あるいはクラス)に self の機能を追加します。

...Module#include の実体であり、
include
を Ruby で書くと以下のように定義できます。

//emlist[例][ruby]{
def include(*modules)
modules.reverse_each do |mod|
# append_features included はプライベートメソッドなので
# 直接 mod.append_features(self)...
...などとは書けない
mod.__send__(:append_features, self)
mod.__send__(:included, self)
end
end
//}

@see Module#included...

Module#included(class_or_module) -> () (6148.0)

self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。

...f が Module#include されたときに対象のクラスまたはモジュー
ルを引数にしてインタプリタがこのメソッドを呼び出します。

@param class_or_module Module#include を実行したオブジェクト

//emlist[例][ruby]{
module Foo
def self.included(mod)
p...
..."#{mod} include #{self}"
end
end
class Bar
include
Foo
end
# => "Bar include Foo"
//}

@see Module#append_features...