るりまサーチ

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

別のキーワード

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

検索結果

<< 1 2 > >>

Module#const_source_location(name, inherited = true) -> [String, Integer] (24408.0)

name で指定した定数の定義を含むソースコードのファイル名と行番号を配列で返します。

...す。

@param name Symbol,String で定数の名前を指定します。
@param inherited true を指定するとスーパークラスや include したモジュールで定義された定数が対象にはなります。false を指定した場合 対象にはなりません。
@return ソース...
...st[例][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.rb", 16...

Module#deprecate_constant(*name) -> self (18314.0)

name で指定した定数を deprecate に設定します。 deprecate に設定した定数を参照すると警告メッセージが表示されます。

...name で指定した定数を deprecate に設定します。
deprecate に設定した定数を参照すると警告メッセージが表示されます。

Ruby
2.7.2 から Warning[:deprecated] のデフォルト値が false に変更になったため、
デフォルトでは警告が表示さ...
...ンオプション(詳細はd:spec/rubycmd#cmd_option参照)で、
「-w」か「-W2」などを指定するか、実行中に「Warning[:deprecated] = true」で
変更すると表示されるようになります。

「$VERBOSE = true」は「Warning[:deprecated]」に影響しないため、
...
...param name 0 個以上の String か Symbol を指定します。

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

@return self を返します。

//emlist[例][ruby]{
FOO = 123
Object.deprecate_constant(:FOO) # => Object

FOO
# warning: constant ::FOO is deprecate...

Module#private_constant(*name) -> self (18308.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#remove_const(name) -> object (18308.0)

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

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

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

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

//emlist[例][ruby]...
...{
class 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#ruby2_keywords(method_name, ...) -> nil (12349.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.

...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...
...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 th...
...ethod 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...

絞り込み条件を変える

Module#module_function(*name) -> Array (12314.0)

メソッドをモジュール関数にします。

...th モジュールのメソッドはすべてモジュール関数です。

単一の引数が与えられた時には与えられた引数をそのまま返します。
複数の引数が与えられた時には配列にまとめて返します。
引数なしの時は nil を返します。

@par...
...am name String または Symbol を 0 個以上指定します。

=== 注意
module
_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモジュールの特異メソッドの 2
つを同時に定義するメ...
...mlist[例][ruby]{
module
M
def foo
p "foo"
end
module
_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo と
プライベートインスタンスメソッド bar...

Module#module_function(name) -> String | Symbol (12314.0)

メソッドをモジュール関数にします。

...th モジュールのメソッドはすべてモジュール関数です。

単一の引数が与えられた時には与えられた引数をそのまま返します。
複数の引数が与えられた時には配列にまとめて返します。
引数なしの時は nil を返します。

@par...
...am name String または Symbol を 0 個以上指定します。

=== 注意
module
_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモジュールの特異メソッドの 2
つを同時に定義するメ...
...mlist[例][ruby]{
module
M
def foo
p "foo"
end
module
_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo と
プライベートインスタンスメソッド bar...

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

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

...す。

@param name String, Symbol で指定される定数名。

@param inherit false を指定するとスーパークラスや include したモジュールで
定義された定数は対象にはなりません。

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

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

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

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

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

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

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

@param name 定数名。String か Symbol で指定します。
完全修飾名を指定しなかった場合はモジュー...
...@param inherit false を指定するとスーパークラスや include したモジュールで
定義された定数は対象にはなりません。

@raise NameError 定数が定義されていないときに発生します。

//emlist[例][ruby]{
module
Bar
BAR = 1
end
class Object...
...r
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...
<< 1 2 > >>