るりまサーチ

最速Rubyリファレンスマニュアル検索!
207件ヒット [101-200件を表示] (0.147秒)
トップページ > クエリ:t[x] > クエリ:Ruby[x] > 種類:インスタンスメソッド[x] > クエリ:on[x] > クラス:Module[x]

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

検索結果

<< < 1 2 3 > >>

Module#const_set(name, value) -> object (12208.0)

モジュールに name で指定された名前の定数を value とい う値として定義し、value を返します。

...@param name Symbol,String で定数の名前を指定します。
@param value セットしたい値を指定します。

//emlist[例][ruby]{
module
Foo; end

# Symbolを指定した場合
Foo.const_set(:FOO, 123)
Foo::FOO # => 123

# Stringを指定した場合
Foo.const_set('BAR', 'abc')
Foo::B...
...れている定数の名前を指定した場合
Foo.const_set('BAR', '123')
# warning: already initialized constant Foo::BAR
# warning: previous definition of BAR was here
# => "123"

# 不適切な定数名を指定した場合
Foo.const_set('foo', 1) # => NameError: wrong constant name foo
//}...

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

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

...inherit に真を指定すると
スーパークラスやインクルードしているモジュールの定数も含みます。
Object のサブクラスの場合、Objectやそのスーパークラスで定義されている
定数は含まれません。 Object.constants とすると Object...
...inherit true を指定するとスーパークラスや include したモジュールで
定義された定数が対象にはなります。false を指定した場合 対象にはなりません。

@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_va...
...iables, Module#class_variables

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

class Foo
FOO = 1
end
class Bar
BAR = 1

# Bar は BAR を含む
p constants...

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

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

...private に変更します。

@param name 0 個以上の String か Symbol を指定します。

@raise NameError 存在しない定数を指定した場合に発生します。

@return self を返します。

@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::QUX referenced
Foo::Quux # => NameError: private constant Foo::Quux referenced
//}...
...可視性を private に変更します。

@param name 0 個以上の String か Symbol を指定します。

@raise NameError 存在しない定数を指定した場合に発生します。

@return self を返します。

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

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

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

...String か Symbol を指定します。

@raise NameError 存在しない定数を指定した場合に発生します。

@return self を返します。

//emlist[例][ruby]{
module
SampleModule
class SampleInnerClass
end

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

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

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

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

@see Module#private_constant, Object#untrusted?...
...nt :SampleInnerClass
end

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

@see Module#private_constant...

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

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

...name String または Symbol を指定します。

@return 引数で指定された定数に設定されていた値を返します。

@raise NameError 引数で指定された定数がそのモジュールやクラスに定義されていない場合に発生します。

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

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

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

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

絞り込み条件を変える

Module#singleton_class? -> bool (12208.0)

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

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

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

Module#ruby2_keywords(method_name, ...) -> nil (6249.0)

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

... the given method names, marks the method as passing keywords through
a normal argument splat. This should only be called on methods that
accept an argument splat (`*args`) but not explicit keywords or a
keyword splat. It marks the method such that if the method is called
with keyword arguments, t...
...ent is marked with a special
flag such that if it is the final element of a normal argument splat to
another method call, and that method call does not include explicit
keywords or a keyword splat, the final element is interpreted as
keywords. In other words, keywords will be passed through the meth...
...od to
other methods.

T
his should only be used for methods that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.

T
his method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby ve...

Module#autoload(const_name, feature) -> nil (6220.0)

定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

...定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

const_name が autoload 設定されていて、まだ定義されてない(ロードされていない)ときは、
autoload する対象を置き換えます。
const_name が(autoload...
...ram const_name String または Symbol で指定します。
なお、const_name には、"::" 演算子を含めることはできません。
つまり、self の直下に定義された定数しか指定できません。

@param feature Kernel.#require と同様な方法で autoloa...
...ist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar
end
end
# ----- end of /tmp/foo.rb ----

class Foo
autoload :Bar, '/tmp/foo'
end
p Foo::Bar #=> Foo::Bar
//}

以下のようにモジュールを明示的にレシーバとして呼び出すこともできます。

//emlist[...

Module#autoload?(const_name) -> String | nil (6208.0)

autoload 定数がまだ定義されてない(ロードされていない) ときにそのパス名を返します。 また、ロード済みなら nil を返します。

...autoload 定数がまだ定義されてない(ロードされていない) ときにそのパス名を返します。
また、ロード済みなら nil を返します。

@param const_name String または Symbol で指定します。

@see Kernel.#autoload?

//emlist[例][ruby]{
autoload :Date, '...
...date'

autoload?(:Date) # => "date"
Date
autoload?(:Date) # => nil
autoload?(:Foo) # => nil
//}...
<< < 1 2 3 > >>