るりまサーチ

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

別のキーワード

  1. bigdecimal/util to_d
  2. float to_d
  3. kernel $-d
  4. openssl d
  5. openssl d=

検索結果

<< 1 2 3 > >>

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

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

...od をインクルードします。

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

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

//emlist[例][ruby]{
module
M
end
module
M2
include
M
end
modu...
...le 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_modules -> [Module] (15208.0)

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

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

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

module
Outer
include
Mixin
end

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

@see Module#ancestors...

Module#included(class_or_module) -> () (12242.0)

self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。

...lf が Module#include されたときに対象のクラスまたはモジュー
ルを引数にしてインタプリタがこのメソッドを呼び出します。

@param class_or_module Module#include を実行したオブジェクト

//emlist[例][ruby]{
module
Foo
d
ef 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 (12221.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#protected_method_defined?(name, inherit=true) -> bool (9214.0)

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

...り、
しかもその可視性が protected であるときに true を返します。
そうでなければ false を返します。

@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義さ...
...ります。

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

//emlist[例][ruby]{
module
A
d
ef method1() end
end
class B
protected
d
ef method2() end
end
class C < B
include
A
d
ef 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 #=> true
C.protected_method_defined? "method2", false #=> false
C.method_defined? "method2" #=> true
//}...

絞り込み条件を変える

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

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

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

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

@param inherit false を指定するとスーパークラスや include したモ...
...by]{
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?(:B...
...AR) # => true

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

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

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

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

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

//emlist[例][ruby]{
d
ef 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#ruby2_keywords(method_name, ...) -> nil (6118.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.

...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, th...
...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
o...
...ther methods.

This should only be used for methods that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.

This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby versions...

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

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

...ted であるときに
true を返します。

@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

@see Module#public_method_defined?, Module#...
...d_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module
A
d
ef method1() end
d
ef protected_method1() end
protected :protected_method1
end
class B
d
ef method2() end
d
ef private_method2() end
private :private_method2
end
class C < B
include
A
d
ef method3() end
end...
...od_defined? :method1 #=> true
C.method_defined? "method1" #=> true
C.method_defined? "method2" #=> true
C.method_defined? "method2", true #=> true
C.method_defined? "method2", false #=> false
C.method_defined? "method3" #=> true
C.method_de...
<< 1 2 3 > >>