るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. psych end_document

検索結果

<< 1 2 3 > >>

Module#include(*mod) -> self (18329.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) -> bool | nil (18168.0)

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

...ee 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 > Prepende...
...d # => true
Prepended > Awesome # => false

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

Module#included(class_or_module) -> () (6266.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#ruby2_keywords(method_name, ...) -> nil (6261.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.

...ot 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.

This should only be used for methods that delegate keywords to another
method, and only for backwards compatibility with Ruby v...
...t 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(:"...
...do_#{meth}", *args, &block)
end

ruby
2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
end

//}...

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

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

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

このメソッドを上書きすることで、prepend の処理を変...
...m mod prepend を呼び出したモジュール
@return mod が返されます

//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


Recorde...
...r::RECORDS # => [A, C]
//}

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

絞り込み条件を変える

Module#include?(mod) -> bool (6245.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#append_features(module_or_class) -> self (6244.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#included_modules -> [Module] (6226.0)

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

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

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


module
Outer
include
Mixin
end


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

@see Module#ancestors...

Module#<=>(other) -> Integer | nil (6138.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
//}...
<< 1 2 3 > >>