るりまサーチ (Ruby 2.7.0)

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

別のキーワード

  1. _builtin include?
  2. socket mcast_include
  3. dbm include?
  4. set include?
  5. sdbm include?

検索結果

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

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

...ます。

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

@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。

//emlist[例][ruby]{
module
M
end
module
M2
include M
end
module
M
include M2
end
//}...
...ールのほうが
先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。

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

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

Module#included(class_or_module) -> () (18424.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 (18361.0)

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

...クラス / 親モジュールがモジュール 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] (18322.0)

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

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

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

module
Outer
include Mixin
end

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

@see Module#ancestors...

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

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

...れた定数は対象にはなりません。


//emlist[例][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
# ユーザ定義...

絞り込み条件を変える

Module#const_get(name, inherit = true) -> object (94.0)

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

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

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

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

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

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

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

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

...ラス)に self の機能を追加します。

このメソッドは Module#include の実体であり、
include を Ruby で書くと以下のように定義できます。

//emlist[例][ruby]{
def include(*modules)
module
s.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#const_source_location(name, inherited = true) -> [String, Integer] (58.0)

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

...が見つからなかった場合は空の配列を返します。

//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 # 定数を...
...] -- Object を継承している為
p M.const_source_location('A') # => ["test.rb", 1] -- Object は継承していないが追加で modules をチェックする

p Object.const_source_location('A::C1') # => ["test.rb", 2] -- ネストの指定もサポートしている
p Object....

Module#ruby2_keywords(method_name, ...) -> nil (52.0)

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

...st in Ruby versions
before 2.7, check that the module responds to this method before calling
it. Also, be aware that if this method is removed, the behavior of the
method will change so that it does not pass through keywords.

//emlist[例][ruby]{
module
Mod
def foo(meth, *args, &block)
send(:...

Module#method_defined?(name, inherit=true) -> bool (40.0)

モジュールにインスタンスメソッド name が定義されており、 かつその可視性が public または protected であるときに true を返します。

...モジュールで
定義されたメソッドも対象になります。

@see Module#public_method_defined?, Module#private_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module
A
def method1() end
def protected_method1() end
protected :protected_method1
end...

絞り込み条件を変える

Module#private_method_defined?(name, inherit=true) -> bool (40.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が private であるときに true を返します。 そうでなければ false を返します。

...したモジュールで
定義されたメソッドも対象になります。

@see Module#method_defined?, Module#public_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module
A
def method1() end
end
class B
private
def method2() end
end
class C < B
includ...

Module#protected_method_defined?(name, inherit=true) -> bool (40.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が protected であるときに true を返します。 そうでなければ false を返します。

...したモジュールで
定義されたメソッドも対象になります。

@see Module#method_defined?, Module#public_method_defined?, Module#private_method_defined?

//emlist[例][ruby]{
module
A
def method1() end
end
class B
protected
def method2() end
end
class C < B
inclu...

Module#public_method_defined?(name, inherit=true) -> bool (40.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が public であるときに true を返します。 そうでなければ false を返します。

...たモジュールで
定義されたメソッドも対象になります。

@see Module#method_defined?, Module#private_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module
A
def method1() end
end
class B
protected
def method2() end
end
class C < B
includ...

Module#<(other) -> bool | nil (22.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 (22.0)

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

...クラス

@raise TypeError other がクラスやモジュールではない場合に発生します。

@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.ancest...

絞り込み条件を変える

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

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

...がクラスやモジュールでなければ
nil を返します。

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

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

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

...@raise TypeError other がクラスやモジュールではない場合に発生します。

@see Module#<

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

Included.ancestors # => [Included, Awesome]
Awesome > Included # => tr...

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

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

...クラス

@raise TypeError other がクラスやモジュールではない場合に発生します。

@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.ancest...

Module#ancestors -> [Class, Module] (22.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#constants(inherit = true) -> [Symbol] (22.0)

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

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

//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.const...
...ない
p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class Baz
# Baz は定数を含まない
p constants # => []

# ネストしたクラスでは、外側のクラスで定義した定数は
# 参照可能なので、BAR は、Module.constant...
...s には含まれる
# (クラス Baz も Bar の定数なので同様)
p Module.constants - $clist # => [:BAR, :Baz, :Foo, :Bar]
end
end
//}...

絞り込み条件を変える

Module#prepend_features(mod) -> self (22.0)

Module#prepend から呼び出されるメソッドで、 prepend の処理の実体です。このメソッド自体は mod で指定した モジュール/クラスの継承チェインの先頭に self を追加します。

...Module#prepend から呼び出されるメソッドで、
prepend の処理の実体です。このメソッド自体は mod で指定した
モジュール/クラスの継承チェインの先頭に self を追加します。

このメソッドを上書きすることで、prepend の処理を変...
...れます

//emlist[例][ruby]{
class Recorder
RECORDS = []
end

module
X
def self.prepend_features(mod)
Recorder::RECORDS << mod
end
end

class A
prepend X
end

class B
include X
end

class C
prepend X
end

Recorder::RECORDS # => [A, C]
//}

@see Module#prepend, Module#prepended...

Module#private_instance_methods(inherited_too = true) -> [Symbol] (22.0)

そのモジュールで定義されている private メソッド名 の一覧を配列で返します。

...ュールで定義されているメソッドのみ返します。

@see Object#private_methods, Module#instance_methods

//emlist[例][ruby]{
module
Foo
def foo; end
private def bar; end
end

module
Bar
include Foo

def baz; end
private def qux; end
end

Bar.private_instance_methods # =>...