るりまサーチ

最速Rubyリファレンスマニュアル検索!
120件ヒット [1-100件を表示] (0.045秒)

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

検索結果

<< 1 2 > >>

Module#singleton_class? -> bool (12233.0)

self が特異クラスの場合に true を返します。そうでなければ false を返し ます。

...self が特異クラスの場合に true を返します。そうでなければ false を返し
ます。

//emlist[例][ruby]{
class
C
end
C.singleton_class? # => false
C.singleton_class.singleton_class? # => true
//}...

Module#const_source_location(name, inherited = true) -> [String, Integer] (12226.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 # 定数を再定義する
end

p B.const_source_location('C4') # =...
...> ["test.rb", 12]
p B.const_source_location('C3') # => ["test.rb", 7]
p B.const_source_location('C1') # => ["test.rb", 2]

p B.const_source_location('C3', false) # => nil -- include したモジュールは検索しない

p A.const_source_location('C2') # => ["test...
...

p Object.const_source_location('B') # => ["test.rb", 10] -- Object はトップレベルの定数を検索する
p Object.const_source_location('A') # => ["test.rb", 1] -- クラスが再定義された場合は最初の定義位置を返す

p B.const_source_location('A')...

Module#constants(inherit = true) -> [Symbol] (6132.0)

そのモジュール(またはクラス)で定義されている定数名の配列を返します。

...ます。
Object のサブクラスの場合、Objectやそのスーパークラスで定義されている
定数は含まれません。 Object.constants とすると Object クラスで定義された
定数の配列が得られます。

得られる定数の順序は保証されません。

@p...
...@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables

//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.constan...
...class Foo
FOO = 1
end
class
Bar
BAR = 1

# Bar は BAR を含む
p constants # => [:BAR]
# 出力に FOO は含まれない
p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class
Baz
# Baz は定数を含まない
p constants...

Module#const_missing(name) (6130.0)

定義されていない定数を参照したときに Ruby インタプリタが このメソッドを呼びます。

... Ruby インタプリタが
このメソッドを呼びます。

@param name 参照した定数名の Symbol

@raise NameError このメソッドを呼び出した場合、デフォルトで発生する例外


//emlist[例][ruby]{
class
Foo
def Foo.const_missing(id)
warn "undefined consta...
...nt #{id.inspect}"
end

Bar
end
Foo::Bar

# => undefined constant :Bar
# undefined constant :Bar
//}...

Module#const_get(name, inherit = true) -> object (6126.0)

name で指定される名前の定数の値を取り出します。

...name で指定される名前の定数の値を取り出します。

Module
#const_defined? と違って Object を特別扱いすることはありません。

@param name 定数名。String か Symbol で指定します。
完全修飾名を指定しなかった場合はモジュー...
...ます。

//emlist[例][ruby]{
module
Bar
BAR = 1
end
class
Object
include Bar
end
# Object では include されたモジュールに定義された定数を見付ける
p Object.const_get(:BAR) # => 1

class
Baz
include Bar
end
# Object以外でも同様
p Baz.const_get(:BAR) # => 1...
...# 定義されていない定数
p Baz.const_get(:NOT_DEFINED) #=> raise NameError
# 第二引数に false を指定すると自分自身に定義された定数から探す
p Baz.const_get(:BAR, false) #=> raise NameError
# 完全修飾名を指定すると include や自分自身へ定義されて...

絞り込み条件を変える

Module#const_defined?(name, inherit = true) -> bool (6120.0)

モジュールに name で指定される名前の定数が定義されている時真 を返します。

...[例][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
# ユーザ定義のモジュールに対しても同様
p Object.const_def...
...ined?(:BAR) # => true

class
Baz
include Bar
end
# Object 以外でも同様になった
# 第二引数のデフォルト値が true であるため
p Baz.const_defined?(:BAR) # => true

# 第二引数を false にした場合
p Baz.const_defined?(:BAR, false) # => false
//}...

Module#private_constant(*name) -> self (6120.0)

name で指定した定数の可視性を private に変更します。

...す。

@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 # => NameError: private constant Foo::Q...
...UX referenced
Foo::Quux # => NameError: private constant Foo::Quux referenced
//}...
...返します。

@see Module#public_constant

//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 # => NameError: private constant Foo::QUX referen...
...ced
Foo::Quux # => NameError: private constant Foo::Quux referenced
//}...

Module#remove_const(name) -> object (6120.0)

name で指定した定数を取り除き、その定数に設定されていた値を 返します。

...そのモジュールやクラスに定義されていない場合に発生します。

//emlist[例][ruby]{
class
Foo
FOO = 1
p remove_const(:FOO) # => 1
p FOO # => uninitialized constant FOO at Foo (NameError)
end
//}

組み込みクラス/モジュールを設定している定数...
...指定した(まだロードしてない)定数を含めて削除する事ができます。

取り除かれた定数は参照できなくなりますが、消える訳ではないので注意して
使用してください。

@see Module#remove_class_variable, Object#remove_instance_variable...

Module#public_constant(*name) -> self (6114.0)

name で指定した定数の可視性を public に変更します。

...t[例][ruby]{
module
SampleModule
class
SampleInnerClass
end

# => 非公開クラスであることを明示するために private にする
private_constant :SampleInnerClass
end

begin
SampleModule::SampleInnerClass
rescue => e
e # => #<NameError: private constant SampleModule::Sampl...
...InnerClass referenced>
end

module
SampleModule
# => 非公開クラスであることは承知で利用するために public にする
public_constant :SampleInnerClass
end

SampleModule::SampleInnerClass # => SampleModule::SampleInnerClass
//}

@see Module#private_constant, Object#untrusted?...
<< 1 2 > >>