るりまサーチ

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

別のキーワード

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

検索結果

<< 1 2 3 > >>

Module#include(*mod) -> self (18170.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#included(class_or_module) -> () (6143.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 (6122.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] (6109.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 (33.0)

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

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

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

@param inherit false を指定するとスーパークラスや include したモ...
...にはなりません。


//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
# ユーザ定義のモジュールに...
...対しても同様
p Object.const_defined?(:BAR) # => true

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

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

絞り込み条件を変える

Module#const_get(name, inherit = true) -> object (33.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#append_features(module_or_class) -> self (21.0)

モジュール(あるいはクラス)に 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] (21.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...
...# => ["test.rb", 7]
p B.const_source_location('C1') # => ["test.rb", 2]

p B.const_source_location('C3', false) # => nil -- include したモジュールは検索しない

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

Module#ruby2_keywords(method_name, ...) -> nil (19.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.

...s 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...
...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 (15.0)

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

...定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

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

//emlist[例][ruby]{
module
A
def method1() end
def protecte...
...d1() end
protected :protected_method1
end
class B
def method2() end
def private_method2() end
private :private_method2
end
class C < B
include
A
def method3() end
end

A.method_defined? :method1 #=> true
C.method_defined? "method1" #=> true
C.method_defined?...

絞り込み条件を変える

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

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

...指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

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

//emlist[例][ruby]{
module
A
def method1() end
end
class B
priva...
...te
def method2() end
end
class C < B
include
A
def method3() end
end

A.method_defined? :method1 #=> true
C.private_method_defined? "method1" #=> false
C.private_method_defined? "method2" #=> true
C.private_method_defined? "method2", true #=> true
C.pri...

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

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

...を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

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

//emlist[例][ruby]{
module
A
def method1() end
end
class B
prot...
...ected
def method2() end
end
class C < B
include
A
def method3() end
end

A.method_defined? :method1 #=> true
C.protected_method_defined? "method1" #=> false
C.protected_method_defined? "method2" #=> true
C.protected_method_defined? "method2", true #=> tru...
<< 1 2 3 > >>