るりまサーチ

最速Rubyリファレンスマニュアル検索!
126件ヒット [1-100件を表示] (0.040秒)
トップページ > クラス:Module[x] > クエリ:Object[x] > クエリ:include[x]

別のキーワード

  1. _builtin each_object
  2. objectspace each_object
  3. object send
  4. object enum_for
  5. object to_enum

ライブラリ

キーワード

検索結果

<< 1 2 > >>

Module#include(*mod) -> self (18180.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#const_get(name, inherit = true) -> object (162.0)

name で指定される名前の定数の値を取り出します。

...name で指定される名前の定数の値を取り出します。

Module
#const_defined? と違って Object を特別扱いすることはありません。

@param name 定数名。String か Symbol で指定します。
完全修飾名を指定しなかった場合はモジュー...
...クラスや include したモジュールで
定義された定数は対象にはなりません。

@raise NameError 定数が定義されていないときに発生します。

//emlist[例][ruby]{
module
Bar
BAR = 1
end
class Object
include
Bar
end
# Object では include された...
...モジュールに定義された定数を見付ける
p Object.const_get(:BAR) # => 1

class Baz
include
Bar
end
# Object以外でも同様
p Baz.const_get(:BAR) # => 1
# 定義されていない定数
p Baz.const_get(:NOT_DEFINED) #=> raise NameError
# 第二引数に false を指定す...

Module#const_defined?(name, inherit = true) -> bool (61.0)

モジュールに name で指定される名前の定数が定義されている時真 を返します。

...クラスや include したモジュールで定義された定数を検索対象
にするかどうかは第二引数で制御することができます。

@param name String, Symbol で指定される定数名。

@param inherit false を指定するとスーパークラスや include したモ...
...例][ruby]{
module
Kernel
FOO = 1
end

# Object include したモジュールの定数に対しても
# true を返す
p Object.const_defined?(:FOO) # => true

module
Bar
BAR = 1
end
class Object
include
Bar
end
# ユーザ定義のモジュールに対しても同様
p Object.const_defi...
...ned?(:BAR) # => true

class Baz
include
Bar
end
# Object 以外でも同様になった
# 第二引数のデフォルト値が true であるため
p Baz.const_defined?(:BAR) # => true

# 第二引数を false にした場合
p Baz.const_defined?(:BAR, false) # => false
//}...

Module#const_source_location(name, inherited = true) -> [String, Integer] (61.0)

name で指定した定数の定義を含むソースコードのファイル名と行番号を配列で返します。

...します。

@param name Symbol,String で定数の名前を指定します。
@param inherited true を指定するとスーパークラスや include したモジュールで定義された定数が対象にはなります。false を指定した場合 対象にはなりません。
@return ソ...
...空の配列を返します。

//emlist[例][ruby]{
# test.rb:
class A # line 1
C1 = 1
C2 = 2
end

module
M # line 6
C3 = 3
end

class B < A # line 10
include
M
C4 = 4
end

class A # 継続して A を定義する
C2 = 8 # 定数を再定義する
end

p B.const_sourc...
...nil -- include したモジュールは検索しない

p A.const_source_location('C2') # => ["test.rb", 16] -- 最後に定義された位置を返す

p Object.const_source_location('B') # => ["test.rb", 10] -- Object はトップレベルの定数を検索する
p Object.const_s...

Module#constants(inherit = true) -> [Symbol] (37.0)

そのモジュール(またはクラス)で定義されている定数名の配列を返します。

...クルードしているモジュールの定数も含みます。
Object
のサブクラスの場合、Objectやそのスーパークラスで定義されている
定数は含まれません。 Object.constants とすると Object クラスで定義された
定数の配列が得られます。...
... include したモジュールで
定義された定数が対象にはなります。false を指定した場合 対象にはなりません。

@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables

//emlist[Module.cons...
...tants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.constants

class Foo
FOO = 1
end
class Bar
BAR = 1

# Bar は BAR を含む
p constants # => [:BAR]
# 出力に FOO...

絞り込み条件を変える

Module#<(other) -> bool | nil (13.0)

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

...list[例][ruby]{
module
Foo
end
class Bar
include
Foo
end
class Baz < Bar
end
class Qux
end
p Bar < Foo # => true
p Baz < Bar # => true
p Baz < Foo # => true
p Baz < Qux # => nil
p Baz > Qux # => nil

p Foo < Object.new # => in `<': compared with non class/module (TypeError)
//...

Module#<=(other) -> bool | nil (13.0)

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

...@see Module#<

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

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

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

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

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

self と 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 (13.0)

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

...ではない場合に発生します。

@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 > Prepended # => true
Prepended > Awesome # => false

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

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

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

...@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 # =>...

絞り込み条件を変える

<< 1 2 > >>