別のキーワード
ライブラリ
- ビルトイン (503)
キーワード
- < (12)
- <= (12)
- <=> (12)
- === (12)
- > (12)
- >= (12)
-
alias
_ method (8) -
append
_ features (12) - autoload (12)
-
class
_ eval (24) -
class
_ exec (12) -
const
_ added (3) -
deprecate
_ constant (12) -
extend
_ object (12) - extended (12)
- freeze (12)
- include (12)
- include? (12)
- included (12)
-
included
_ modules (12) -
instance
_ method (12) -
module
_ eval (24) -
module
_ exec (12) - prepend (12)
-
prepend
_ features (12) - prepended (12)
-
private
_ class _ method (24) -
private
_ constant (12) - public (48)
-
public
_ class _ method (24) -
public
_ constant (12) -
public
_ instance _ method (12) -
remove
_ method (12) -
singleton
_ class? (12) -
undef
_ method (12) - using (12)
検索結果
先頭5件
-
Module
# extend _ object(obj) -> object (56.0) -
Object#extend の実体です。オブジェクトにモジュールの機能を追加します。
...す。
Object#extend は、Ruby で書くと以下のように定義できます。
//emlist[例][ruby]{
def extend(*modules)
modules.reverse_each do |mod|
# extend_object や extended はプライベートメソッドなので
# 直接 mod.extend_object(self) などとは書けない......mod.__send__(:extend_object, self)
mod.__send__(:extended, self)
end
end
//}
extend_object のデフォルトの実装では、self に定義されて
いるインスタンスメソッドを obj の特異メソッドとして追加します。
@param obj self の機能を追加するオブ......ジェクトを指定します。
@return obj で指定されたオブジェクトを返します。
@see Module#extended... -
Module
# ===(obj) -> bool (52.0) -
指定された obj が self かそのサブクラスのインスタンスであるとき真を返します。 また、obj が self をインクルードしたクラスかそのサブクラスのインスタンスである場合にも 真を返します。上記のいずれでもない場合に false を返します。
...指定された obj が self かそのサブクラスのインスタンスであるとき真を返します。
また、obj が self をインクルードしたクラスかそのサブクラスのインスタンスである場合にも
真を返します。上記のいずれでもない場合に fa......替えると obj.kind_of?(self) が true の場合、 true を返します。
このメソッドは主に case 文での比較に用いられます。
case ではクラス、モジュールの所属関係をチェックすることになります。
//emlist[例][ruby]{
str = String.new
case str
w... -
Module
# <=>(other) -> Integer | nil (48.0) -
self と other の継承関係を比較します。
...
self と other の継承関係を比較します。
self と other を比較して、
self が other の子孫であるとき -1、
同一のクラス/モジュールのとき 0、
self が other の先祖であるとき 1
を返します。
継承関係にないクラス同士の比較では
n......er がクラスやモジュールでなければ
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 (46.0) -
比較演算子。self が other の子孫である場合、 true を返します。 self が other の先祖か同一のクラス/モジュールである場合、false を返します。
...比較演算子。self が other の子孫である場合、 true を返します。
self が other の先祖か同一のクラス/モジュールである場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param other 比較対象のモ....../emlist[例][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 (46.0) -
比較演算子。 self が other の先祖である場合、true を返します。 self が other の子孫か同一クラスである場合、false を返します。
...比較演算子。 self が other の先祖である場合、true を返します。
self が other の子孫か同一クラスである場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param other 比較対象のモジュールやクラ......@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 (46.0) -
比較演算子。self が other の先祖か同一クラスである場合、 true を返します。 self が other の子孫である場合、false を返します。
...比較演算子。self が other の先祖か同一クラスである場合、 true を返します。
self が other の子孫である場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param other 比較対象のモジュールやクラ......ス
@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.ancestors #... -
Module
# autoload(const _ name , feature) -> nil (44.0) -
定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。
...を含めることはできません。
つまり、self の直下に定義された定数しか指定できません。
@param feature Kernel.#require と同様な方法で autoload する対象を指定する。
//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar......Foo::Bar #=> Foo::Bar
//}
以下のようにモジュールを明示的にレシーバとして呼び出すこともできます。
//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar
end
end
# ----- end of /tmp/foo.rb ----
class Foo
end
Foo.autoload :Bar, '/tmp/foo'
p Fo......下のように、autoload したライブラリがネストした定数を定義しない場
合、NameError が発生します。
//emlist[例][ruby]{
# ------- /tmp/bar.rb ---------
class Bar
end
# ----- end of /tmp/bar.rb ----
class Foo
autoload :Bar, '/tmp/bar.rb'
end
p Foo::Bar
#=> -:4:in... -
Module
# extended(obj) -> () (42.0) -
self が他のオブジェクト に Object#extend されたときに 呼ばれます。引数には extend を行ったオブジェクトが渡されます。
...
self が他のオブジェクト に Object#extend されたときに
呼ばれます。引数には extend を行ったオブジェクトが渡されます。
@param obj Object#extend を行ったオブジェクト
//emlist[例][ruby]{
module Foo
def self.extended(obj)
p "#{obj} extend #{s......elf}"
end
end
Object.new.extend Foo
# => "#<Object:0x401cbc3c> extend Foo"
//}
@see Module#extend_object... -
Module
# included(class _ or _ module) -> () (42.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...