294件ヒット
[1-100件を表示]
(0.049秒)
ライブラリ
- ビルトイン (294)
キーワード
- < (12)
- <= (12)
- <=> (12)
- === (12)
- >= (12)
-
class
_ eval (24) -
class
_ exec (12) -
deprecate
_ constant (12) -
extend
_ object (12) - extended (12)
- freeze (12)
- include (12)
-
instance
_ method (12) -
module
_ eval (24) -
module
_ exec (12) -
private
_ constant (9) - public (48)
-
public
_ constant (9) -
public
_ instance _ method (12)
検索結果
先頭5件
-
Module
# >(other) -> bool | nil (18175.0) -
比較演算子。 self が other の先祖である場合、true を返します。 self が other の子孫か同一クラスである場合、false を返します。
...比較演算子。 self が other の先祖である場合、true を返します。
self が other の子孫か同一クラスである場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param other 比較対象のモジュールやクラ......@see Module#<
//emlist[例][ruby]{
module Awesome; end
module Included
include Awesome
end
module Prepended
prepend Awesome
end
Included.ancestors # => [Included, Awesome]
Awesome > Included # => true
Included > Awesome # => false
Prepended.ancestors # => [Awesome, Prepended]
Awesome > Prep......ended # => true
Prepended > Awesome # => false
Awesome > Awesome # => false
Awesome > Object # => nil
//}... -
Module
# extend _ object(obj) -> object (6379.0) -
Object#extend の実体です。オブジェクトにモジュールの機能を追加します。
...
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
# <=>(other) -> Integer | nil (6141.0) -
self と other の継承関係を比較します。
...
self と other の継承関係を比較します。
self と other を比較して、
self が other の子孫であるとき -1、
同一のクラス/モジュールのとき 0、
self が other の先祖であるとき 1
を返します。
継承関係にないクラス同士の比較では
n......のクラスやモジュール
//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
//}... -
Module
# >=(other) -> bool | nil (6139.0) -
比較演算子。self が other の先祖か同一クラスである場合、 true を返します。 self が other の子孫である場合、false を返します。
...比較演算子。self が other の先祖か同一クラスである場合、 true を返します。
self が other の子孫である場合、false を返します。
継承関係にないクラス同士の比較では
nil を返します。
@param 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 # => [Foo, Baz]
Foo >= Baz # => true
Baz >= Foo # => false
Foo >= Foo # => true
Foo >= Object # => ni... -
Module
# deprecate _ constant(*name) -> self (232.0) -
name で指定した定数を deprecate に設定します。 deprecate に設定した定数を参照すると警告メッセージが表示されます。
...い定数を指定した場合に発生します。
@return self を返します。
//emlist[例][ruby]{
FOO = 123
Object.deprecate_constant(:FOO) # => Object
FOO
# warning: constant ::FOO is deprecated
# => 123
Object.deprecate_constant(:BAR)
# NameError: constant Object::BAR not defined
//}... -
Module
# public _ constant(*name) -> self (220.0) -
name で指定した定数の可視性を public に変更します。
...@return self を返します。
//emlist[例][ruby]{
module SampleModule
class SampleInnerClass
end
# => 非公開クラスであることを明示するために private にする
private_constant :SampleInnerClass
end
begin
SampleModule::SampleInnerClass
rescue => e
e # => #<NameE......stant SampleModule::SampleInnerClass referenced>
end
module SampleModule
# => 非公開クラスであることは承知で利用するために public にする
public_constant :SampleInnerClass
end
SampleModule::SampleInnerClass # => SampleModule::SampleInnerClass
//}
@see Module#private_co... -
Module
# include(*mod) -> self (214.0) -
モジュール mod をインクルードします。
...ます。
@param mod Module のインスタンス( Enumerable など)を指定します。
@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。
//emlist[例][ruby]{
module M
end
module M2
include M
end
module M
include M2
end
//}......られており、 mix-in とも呼びます。
//emlist[例][ruby]{
class C
include FileTest
include Math
end
p C.ancestors
# => [C, Math, FileTest, Object, Kernel]
//}
モジュールの機能追加は、クラスの継承関係の間にそのモジュールが挿入
されることで実......ールのほうが
先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。
同じモジュールを二回以上 include すると二回目以降は無視されます。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
include... -
Module
# private _ constant(*name) -> self (214.0) -
name で指定した定数の可視性を private に変更します。
...@return self を返します。
@see Module#public_constant, Object#untrusted?
//emlist[例][ruby]{
module Foo
BAR = 'bar'
class Baz; end
QUX = 'qux'
class Quux; end
private_constant :QUX
private_constant :Quux
end
Foo::BAR # => "bar"
Foo::Baz # => Foo::Baz
Foo::QUX # => NameErr......or: private constant Foo::QUX referenced
Foo::Quux # => NameError: private constant Foo::Quux referenced
//}... -
Module
# class _ eval {|mod| . . . } -> object (211.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...トで評価するとは、実行中そのモジュールが self になるということです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。......s C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
//emlist[定数のスコープが異なる例][ruby]{
class C
end
# ブロックが渡された場合は、ブロックの外側のス......列が渡された場合は、モジュール定義式内と同じスコープになる。つまり、この場合は
# class C
# X = 2
# end
# と書いたのと同じ意味になる。
C.class_eval 'X = 2'
p X #=> 1
p C::X #=> 2
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval...