別のキーワード
種類
- インスタンスメソッド (396)
- 特異メソッド (24)
ライブラリ
- ビルトイン (420)
キーワード
- < (12)
- <= (12)
- <=> (12)
- > (12)
- >= (12)
-
append
_ features (12) - autoload? (12)
-
class
_ eval (24) -
class
_ exec (12) -
extend
_ object (12) - inspect (12)
-
instance
_ method (12) -
module
_ eval (24) -
module
_ exec (12) -
module
_ function (36) - name (12)
- new (24)
- private (48)
- protected (48)
- public (48)
-
to
_ s (12)
検索結果
先頭5件
-
Module
. new {|mod| . . . } -> Module (108.0) -
名前の付いていないモジュールを新しく生成して返します。
...ジュールのコンテキストでブロックを実行します。
//emlist[例][ruby]{
mod = Module.new
mod.module_eval {|m|
# ...
}
mod
//}
と同じです。
ブロックの実行は Module#initialize が行います。
ブロックを与えた場合も生成したモジュールを返し......ュールの名前は、
そのモジュールが代入されている定数名のいずれかです。
//emlist[例][ruby]{
m = Module.new
p m # => #<Module 0lx40198a54>
p m.name # => nil # まだ名前は未定
Foo = m
# m.name # ここで m.name を呼べば m... -
Module
# class _ eval {|mod| . . . } -> object (103.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
定数とクラス変数のスコープは、文字列が与えられた場合と......列が渡された場合は、モジュール定義式内と同じスコープになる。つまり、この場合は
# 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... -
Module
# class _ exec(*args) {|*vars| . . . } -> object (103.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 _ eval {|mod| . . . } -> object (103.0) -
モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。
...ことです。
つまり、そのモジュールの定義式の中にあるかのように実行されます。
ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。
定数とクラス変数のスコープは、文字列が与えられた場合と......列が渡された場合は、モジュール定義式内と同じスコープになる。つまり、この場合は
# 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... -
Module
# module _ exec(*args) {|*vars| . . . } -> object (103.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 (102.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 (102.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 (102.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 (102.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...