5件ヒット
[1-5件を表示]
(0.031秒)
検索結果
先頭5件
-
Module
# included(class _ or _ module) -> () (54967.0) -
self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。
self が 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_featu... -
Module
# ancestors -> [Class , Module] (682.0) -
クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。
クラス、モジュールのスーパークラスとインクルードしているモジュール
を優先順位順に配列に格納して返します。
//emlist[例][ruby]{
module Foo
end
class Bar
include Foo
end
class Baz < Bar
p ancestors
p included_modules
p superclass
end
# => [Baz, Bar, Foo, Object, Kernel, BasicObject]
# => [Foo, Kernel]
# => Bar
//}
@see Module#included_modules
... -
Module
# append _ features(module _ or _ class) -> self (664.0) -
モジュール(あるいはクラス)に self の機能を追加します。
モジュール(あるいはクラス)に 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, s... -
Module
# prepended(class _ or _ module) -> () (646.0) -
self が Module#prepend されたときに対象のクラスまたはモジュールを 引数にしてインタプリタがこのメソッドを呼び出します。
self が Module#prepend されたときに対象のクラスまたはモジュールを
引数にしてインタプリタがこのメソッドを呼び出します。
@param class_or_module Module#prepend を実行したオブジェクト
//emlist[例][ruby]{
module A
def self.prepended(mod)
puts "#{self} prepended to #{mod}"
end
end
module Enumerable
prepend A
end
# => "A prepended to Enumerable"
//}
@... -
Object
# extend(*modules) -> self (361.0) -
引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。
引数で指定したモジュールのインスタンスメソッドを self の特異
メソッドとして追加します。
Module#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を追加
したいときに使用します。
引数に複数のモジュールを指定した場合、最後
の引数から逆順に extend を行います。
@param modules モジュールを任意個指定します(クラスは不可)。
@return self を返します。
//emlist[][ruby]{
module Foo
def a
'ok Foo'
en...