ライブラリ
- ビルトイン (6)
キーワード
-
const
_ source _ location (2) - constants (1)
-
included
_ modules (1) -
prepend
_ features (1) -
undef
_ method (1)
検索結果
先頭5件
-
Module
# undef _ method(*name) -> self (24043.0) -
このモジュールのインスタンスメソッド name を未定義にします。
...名を String または Symbol で与えられることです。
module M1
def foo
end
def self.moo
undef foo
end
end
M1.instance_methods false #=> ["foo"]
M1.moo
M1.instance_methods false #=> []
module M2
def foo
end
def self.moo
undef_method :fo... -
Module
# const _ source _ location(str , inherit=true) -> [String , Integer] (24025.0) -
Returns the Ruby source filename and line number containing the definition of the constant specified. If the named constant is not found, `nil` is returned. If the constant is found, but its source location can not be extracted (constant is defined in C code), empty array is returned.
...* specifies whether to lookup in `mod.ancestors` (`true` by
default).
//emlist[][ruby]{
# test.rb:
class A # line 1
C1 = 1
C2 = 2
end
module M # line 6
C3 = 3
end
class B < A # line 10
include M
C4 = 4
end
class A # continuation of A definition
C2 = 8 # constant re......cause Object is in ancestors
p M.const_source_location('A') # => ["test.rb", 1] -- Object is not ancestor, but additionally checked for modules
p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported
p Object.const_source_location('String') # => [] -- co... -
Module
# const _ source _ location(sym , inherit=true) -> [String , Integer] (24025.0) -
Returns the Ruby source filename and line number containing the definition of the constant specified. If the named constant is not found, `nil` is returned. If the constant is found, but its source location can not be extracted (constant is defined in C code), empty array is returned.
...* specifies whether to lookup in `mod.ancestors` (`true` by
default).
//emlist[][ruby]{
# test.rb:
class A # line 1
C1 = 1
C2 = 2
end
module M # line 6
C3 = 3
end
class B < A # line 10
include M
C4 = 4
end
class A # continuation of A definition
C2 = 8 # constant re......cause Object is in ancestors
p M.const_source_location('A') # => ["test.rb", 1] -- Object is not ancestor, but additionally checked for modules
p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported
p Object.const_source_location('String') # => [] -- co... -
Module
# constants(inherit = true) -> [Symbol] (24025.0) -
そのモジュール(またはクラス)で定義されている定数名の配列を返します。
...ん。
@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables
Module.constants と Module#constants の違い
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.constants......p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class Baz
# Baz は定数を含まない
p constants # => []
# ネストしたクラスでは、外側のクラスで定義した定数は
# 参照可能なので、BAR は、Module.con......stants には含まれる
# (クラス Baz も Bar の定数なので同様)
p Module.constants - $clist # => [:BAR, :Baz, :Foo, :Bar]
end
end... -
Module
# included _ modules -> [Module] (24025.0) -
self にインクルードされているモジュールの配列を返します。
...インクルードされているモジュールの配列を返します。
module Mixin
end
module Outer
include Mixin
end
Mixin.included_modules #=> []
Outer.included_modules #=> [Mixin]
@see Module#ancestors... -
Module
# prepend _ features(mod) -> self (24025.0) -
Module#prepend から呼び出されるメソッドで、 prepend の処理の実体です。このメソッド自体は mod で指定した モジュール/クラスの継承チェインの先頭に self を追加します。
...Module#prepend から呼び出されるメソッドで、
prepend の処理の実体です。このメソッド自体は mod で指定した
モジュール/クラスの継承チェインの先頭に self を追加します。
このメソッドを上書きすることで、prepend の処理を変......れます
//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
Recorder::RECORDS # => [A, C]
//}
@see Module#prepend, Module#prepended...