るりまサーチ

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

別のキーワード

  1. argf.class each_line
  2. argf.class each
  3. argf.class lines
  4. argf.class readline
  5. argf.class readlines

検索結果

<< < 1 2 3 >>

Module#const_defined?(name, inherit = true) -> bool (43.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#<(other) -> bool | nil (31.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#include(*mod) -> self (31.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) -> Integer | nil (25.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#private_constant(*name) -> self (19.0)

name で指定した定数の可視性を private に変更します。

...数を指定した場合に発生します。

@return self を返します。

@see Module#public_constant, Object#untrusted?

//emlist[例][ruby]{
module
Foo
BAR = 'bar'
class
Baz; end
QUX = 'qux'
class
Quux; end

private_constant :QUX
private_constant :Quux
end

Foo::BAR # => "bar"
F...

絞り込み条件を変える

Module.constants -> [Symbol] (19.0)

このメソッドを呼び出した時点で参照可能な定数名の配列を返します。

...//emlist[例][ruby]{
class
C
FOO = 1
end
p Module.constants # => [:RUBY_PLATFORM, :STDIN, ..., :C, ...]
# 出力中に :FOO は現われない
//}

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

Module#instance_method(name) -> UnboundMethod (13.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...します。

@raise NameError self に存在しないメソッドを指定した場合に発生します。

@see Module#public_instance_method, Object#method

//emlist[例][ruby]{
class
Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; en...

Module#public_constant(*name) -> self (13.0)

name で指定した定数の可視性を public に変更します。

...{
module
SampleModule
class
SampleInnerClass
end

# => 非公開クラスであることを明示するために private にする
private_constant :SampleInnerClass
end

begin
SampleModule::SampleInnerClass
rescue => e
e # => #<NameError: private constant SampleModule::SampleInnerClass...
...referenced>
end

module
SampleModule
# => 非公開クラスであることは承知で利用するために public にする
public_constant :SampleInnerClass
end

SampleModule::SampleInnerClass # => SampleModule::SampleInnerClass
//}

@see Module#private_constant, Object#untrusted?...
<< < 1 2 3 >>