るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

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

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

...ます。

@
param mod Module のインスタンス( Enumerable など)を指定します。

@
raise ArgumentError 継承関係が循環してしまうような 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]
//}

モジュールの機能追加は、クラスの継承関係の間にそのモジュールが挿入
される...

Module#>(other) -> bool | nil (18305.0)

比較演算子。 self が other の先祖である場合、true を返します。 self が other の子孫か同一クラスである場合、false を返します。

...子。 self が other の先祖である場合、true を返します。
self
が other の子孫か同一クラスである場合、false を返します。

継承関係にないクラス同士の比較では
nil を返します。

@
param other 比較対象のモジュールやクラス

@
raise T...
...

@
see Module#<

//emlist[例][ruby]{
module Awesome; end
module Included
include
Awesome
end
module Prepended
prepend Awesome
end

Include
d.ancestors # => [Included, Awesome]
Awesome > Included # => true
Include
d > Awesome # => false

Prepended.ancestors # => [Awesome, Prepended]
Awesome > P...
...repended # => true
Prepended > Awesome # => false

Awesome > Awesome # => false
Awesome > Object # => nil
//}...

Module#included(class_or_module) -> () (6393.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_features...

Module#include?(mod) -> bool (6354.0)

self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返します。

...
self
かその親クラス / 親モジュールがモジュール mod を
インクルードしていれば true を返します。

@
param mod Module を指定します。

//emlist[例][ruby]{
module M
end
class C1
include
M
end
class C2 < C1
end

p C1.include?(M) # => true
p C2.include?(M)...
...# => true
//}...

Module#included_modules -> [Module] (6341.0)

self にインクルードされているモジュールの配列を返します。

...
self
にインクルードされているモジュールの配列を返します。

//emlist[例][ruby]{
module Mixin
end

module Outer
include
Mixin
end

Mixin.included_modules #=> []
Outer.included_modules #=> [Mixin]
//}

@
see Module#ancestors...

絞り込み条件を変える

Module#<=>(other) -> Integer | nil (6283.0)

self と other の継承関係を比較します。

...
self
と other の継承関係を比較します。

self
と other を比較して、
self
が other の子孫であるとき -1、
同一のクラス/モジュールのとき 0、
self
が other の先祖であるとき 1
を返します。

継承関係にないクラス同士の比較では
n...
...

@
param other 比較対象のクラスやモジュール

//emlist[例][ruby]{
module Foo
end
class Bar
include
Foo
end
class Baz < Bar
end
class Qux
end
p Bar <=> Foo # => -1
p Baz <=> Bar # => -1
p Baz <=> Foo # => -1
p Baz <=> Qux # => nil
p Qux <=> Baz # => nil

p Baz <=>...
...Object.new # => nil
//}...

Module#>=(other) -> bool | nil (6269.0)

比較演算子。self が other の先祖か同一クラスである場合、 true を返します。 self が other の子孫である場合、false を返します。

...子。self が other の先祖か同一クラスである場合、 true を返します。
self
が other の子孫である場合、false を返します。

継承関係にないクラス同士の比較では
nil を返します。

@
param other 比較対象のモジュールやクラス

@
raise T...
...

@
see Module#<

//emlist[例][ruby]{
module Foo; end
module Bar
include
Foo
end
module Baz
prepend Foo
end

Bar.ancestors # => [Bar, Foo]
Foo >= Bar # => true
Bar >= Foo # => false

Baz.ancestors # => [Foo, Baz]
Foo >= Baz # => true
Baz >= Foo # => false

Foo >= Foo # => true
Foo >= Object # =>...

Object#extend(*modules) -> self (396.0)

引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。

...引数で指定したモジュールのインスタンスメソッドを self の特異
メソッドとして追加します。

Module#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を...
...

@
param modules モジュールを任意個指定します(クラスは不可)。
@
return self を返します。

//emlist[][ruby]{
module Foo
def a
'ok Foo'
end
end

module Bar
def b
'ok Bar'
end
end

obj = Object.new
obj.extend Foo, Bar
p obj.a #=> "ok Foo"
p obj.b #=> "ok...
...Bar"

class Klass
include
Foo
extend Bar
end

p Klass.new.a #=> "ok Foo"
p Klass.b #=> "ok Bar"
//}

extend の機能は、「特異クラスに対する Module#include
と言い替えることもできます。
ただしその場合、フック用のメソッド
が Module#extended で...

Module#append_features(module_or_class) -> self (384.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, self)
mod.__send__(:included, self)
end
end
//}

@
see Module#included...
<< 1 2 3 > >>