ライブラリ
- ビルトイン (13)
キーワード
- < (1)
- <= (1)
- <=> (1)
- > (1)
- >= (1)
-
class
_ eval (2) -
class
_ exec (1) -
extend
_ object (1) -
instance
_ method (1) -
module
_ eval (2) -
module
_ exec (1)
検索結果
先頭5件
-
Module
# extend _ object(obj) -> object (18787.0) -
Object#extend の実体です。オブジェクトにモジュールの機能を追加します。
...機能を追加します。
Object#extend は、Ruby で書くと以下のように定義できます。
//emlist[例][ruby]{
def extend(*modules)
modules.reverse_each do |mod|
# extend_object や extended はプライベートメソッドなので
# 直接 mod.extend_object(self) など......では、self に定義されて
いるインスタンスメソッドを obj の特異メソッドとして追加します。
@param obj self の機能を追加するオブジェクトを指定します。
@return obj で指定されたオブジェクトを返します。
@see Module#extended... -
Module
# class _ eval {|mod| . . . } -> object (625.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
文字列が与えられた場合には、定数とクラス変数のスコープ......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
Module
# module _ eval {|mod| . . . } -> object (625.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
文字列が与えられた場合には、定数とクラス変数のスコープ......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
Module
# class _ exec(*args) {|*vars| . . . } -> object (619.0) -
与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。
...ing.class_exec{
def hello()
"Hello there!"
end
define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}
t = Thing.new
p t.hello() #=> "Hello there!"
p t.foo() #=> 1
//}
@see Module#module_eval, Module#class_eval... -
Module
# module _ exec(*args) {|*vars| . . . } -> object (619.0) -
与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。
...ing.class_exec{
def hello()
"Hello there!"
end
define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}
t = Thing.new
p t.hello() #=> "Hello there!"
p t.foo() #=> 1
//}
@see Module#module_eval, Module#class_eval... -
Module
# <(other) -> bool | nil (328.0) -
比較演算子。self が other の子孫である場合、 true を返します。 self が other の先祖か同一のクラス/モジュールである場合、false を返します。
...list[例][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 (328.0) -
比較演算子。self が other の子孫であるか、self と other が 同一クラスである場合、 true を返します。 self が other の先祖である場合、false を返します。
...クラス
@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 # => false
Bar <= Foo # => true
Baz.ancest... -
Module
# <=>(other) -> Integer | nil (328.0) -
self と other の継承関係を比較します。
...がクラスやモジュールでなければ
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 (328.0) -
比較演算子。 self が other の先祖である場合、true を返します。 self が other の子孫か同一クラスである場合、false を返します。
...@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 (328.0) -
比較演算子。self が other の先祖か同一クラスである場合、 true を返します。 self が other の子孫である場合、false を返します。
...クラス
@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.ancest... -
Module
# class _ eval(expr , fname = "(eval)" , lineno = 1) -> object (325.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
文字列が与えられた場合には、定数とクラス変数のスコープ......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
Module
# module _ eval(expr , fname = "(eval)" , lineno = 1) -> object (325.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
文字列が与えられた場合には、定数とクラス変数のスコープ......などを差し替えることができます。
//emlist[例][ruby]{
class C
end
a = 1
C.class_eval %Q{
def m # メソッドを動的に定義できる。
return :m, #{a}
end
}
p C.new.m #=> [:m, 1]
//}
@see BasicObject#instance_eval, Module.new, Kernel.#eval... -
Module
# instance _ method(name) -> UnboundMethod (43.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...Symbol または String で指定します。
@raise NameError self に存在しないメソッドを指定した場合に発生します。
@see Module#public_instance_method, Object#method
//emlist[例][ruby]{
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end...