ライブラリ
- ビルトイン (12)
キーワード
- < (1)
- <= (1)
- <=> (1)
- > (1)
- >= (1)
- ancestors (1)
-
const
_ defined? (1) -
const
_ get (1) -
const
_ source _ location (1) - constants (1)
-
private
_ instance _ methods (1)
検索結果
先頭5件
-
Module
# include(*mod) -> self (54544.0) -
モジュール mod をインクルードします。
...ます。
@param mod Module のインスタンス( Enumerable など)を指定します。
@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。
//emlist[例][ruby]{
module M
end
module M2
include M
end
module M
include M2
end
//}......ールのほうが
先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。
同じモジュールを二回以上 include すると二回目以降は無視されます。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
include... -
Module
# const _ get(name , inherit = true) -> object (490.0) -
name で指定される名前の定数の値を取り出します。
...name で指定される名前の定数の値を取り出します。
Module#const_defined? と違って Object を特別扱いすることはありません。
@param name 定数名。String か Symbol で指定します。
完全修飾名を指定しなかった場合はモジュー......れた定数は対象にはなりません。
@raise NameError 定数が定義されていないときに発生します。
//emlist[例][ruby]{
module Bar
BAR = 1
end
class Object
include Bar
end
# Object では include されたモジュールに定義された定数を見付ける
p Object.... -
Module
# const _ defined?(name , inherit = true) -> bool (187.0) -
モジュールに name で指定される名前の定数が定義されている時真 を返します。
...れた定数は対象にはなりません。
//emlist[例][ruby]{
module Kernel
FOO = 1
end
# Object は include したモジュールの定数に対しても
# true を返す
p Object.const_defined?(:FOO) # => true
module Bar
BAR = 1
end
class Object
include Bar
end
# ユーザ定義... -
Module
# const _ source _ location(name , inherited = true) -> [String , Integer] (187.0) -
name で指定した定数の定義を含むソースコードのファイル名と行番号を配列で返します。
...が見つからなかった場合は空の配列を返します。
//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 # 継続して A を定義する
C2 = 8 # 定数を......] -- Object を継承している為
p M.const_source_location('A') # => ["test.rb", 1] -- Object は継承していないが追加で modules をチェックする
p Object.const_source_location('A::C1') # => ["test.rb", 2] -- ネストの指定もサポートしている
p Object.... -
Module
# constants(inherit = true) -> [Symbol] (115.0) -
そのモジュール(またはクラス)で定義されている定数名の配列を返します。
...@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables
//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.const......ない
p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class Baz
# Baz は定数を含まない
p constants # => []
# ネストしたクラスでは、外側のクラスで定義した定数は
# 参照可能なので、BAR は、Module.constant......s には含まれる
# (クラス Baz も Bar の定数なので同様)
p Module.constants - $clist # => [:BAR, :Baz, :Foo, :Bar]
end
end
//}... -
Module
# <(other) -> bool | nil (43.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 (43.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 (43.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 (43.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 (43.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
# ancestors -> [Class , Module] (43.0) -
クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。
...先順位順に配列に格納して返します。
//emlist[例][ruby]{
module Foo
end
class Bar
include Foo
end
class Baz < Bar
p ancestors
p included_modules
p superclass
end
# => [Baz, Bar, Foo, Object, Kernel, BasicObject]
# => [Foo, Kernel]
# => Bar
//}
@see Module#included_modules... -
Module
# private _ instance _ methods(inherited _ too = true) -> [Symbol] (43.0) -
そのモジュールで定義されている private メソッド名 の一覧を配列で返します。
...ュールで定義されているメソッドのみ返します。
@see Object#private_methods, Module#instance_methods
//emlist[例][ruby]{
module Foo
def foo; end
private def bar; end
end
module Bar
include Foo
def baz; end
private def qux; end
end
Bar.private_instance_methods # =>...