別のキーワード
ライブラリ
- ビルトイン (207)
キーワード
- autoload (12)
- autoload? (12)
-
const
_ added (3) -
const
_ defined? (12) -
const
_ get (12) -
const
_ missing (12) -
const
_ set (12) -
const
_ source _ location (12) - constants (12)
-
deprecate
_ constant (12) -
module
_ function (36) -
private
_ constant (12) -
public
_ constant (12) -
remove
_ const (12) -
ruby2
_ keywords (12) -
singleton
_ class? (12)
検索結果
先頭5件
-
Module
# const _ source _ location(name , inherited = true) -> [String , Integer] (18314.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......", 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
# ruby2 _ keywords(method _ name , . . . ) -> nil (12380.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.
This should only be used for methods that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.
This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby ve... -
Module
# const _ missing(name) (12246.0) -
定義されていない定数を参照したときに Ruby インタプリタが このメソッドを呼びます。
... Ruby インタプリタが
このメソッドを呼びます。
@param name 参照した定数名の Symbol
@raise NameError このメソッドを呼び出した場合、デフォルトで発生する例外
//emlist[例][ruby]{
class Foo
def Foo.const_missing(id)
warn "undefined constant......#{id.inspect}"
end
Bar
end
Foo::Bar
# => undefined constant :Bar
# undefined constant :Bar
//}... -
Module
# deprecate _ constant(*name) -> self (12226.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]」に影響しないため、
表......tring か Symbol を指定します。
@raise NameError 存在しない定数を指定した場合に発生します。
@return self を返します。
//emlist[例][ruby]{
FOO = 123
Object.deprecate_constant(:FOO) # => Object
FOO
# warning: constant ::FOO is deprecated
# => 123
Object.deprecat... -
Module
# module _ function() -> nil (12226.0) -
メソッドをモジュール関数にします。
...は、プライベートメソッドであると同時に
モジュールの特異メソッドでもあるようなメソッドです。
例えば Math モジュールのメソッドはすべてモジュール関数です。
単一の引数が与えられた時には与えられた引数をその......た時には配列にまとめて返します。
引数なしの時は nil を返します。
@param name String または Symbol を 0 個以上指定します。
=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プラ......ジュール関数の別名は定義できません。
//emlist[例][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... -
Module
# module _ function(*name) -> Array (12226.0) -
メソッドをモジュール関数にします。
...は、プライベートメソッドであると同時に
モジュールの特異メソッドでもあるようなメソッドです。
例えば Math モジュールのメソッドはすべてモジュール関数です。
単一の引数が与えられた時には与えられた引数をその......た時には配列にまとめて返します。
引数なしの時は nil を返します。
@param name String または Symbol を 0 個以上指定します。
=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プラ......ジュール関数の別名は定義できません。
//emlist[例][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... -
Module
# module _ function(name) -> String | Symbol (12226.0) -
メソッドをモジュール関数にします。
...は、プライベートメソッドであると同時に
モジュールの特異メソッドでもあるようなメソッドです。
例えば Math モジュールのメソッドはすべてモジュール関数です。
単一の引数が与えられた時には与えられた引数をその......た時には配列にまとめて返します。
引数なしの時は nil を返します。
@param name String または Symbol を 0 個以上指定します。
=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プラ......ジュール関数の別名は定義できません。
//emlist[例][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... -
Module
# const _ added(name) -> () (12214.0) -
定数 name が追加された時にインタプリタがこのメソッドを呼び出します。
...定数 name が追加された時にインタプリタがこのメソッドを呼び出します。
//emlist[][ruby]{
module Chatty
def self.const_added(const_name)
super
puts "Added #{const_name.inspect}"
end
FOO = 1
end
# => Added :FOO
//}... -
Module
# const _ defined?(name , inherit = true) -> bool (12214.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 (12214.0) -
name で指定される名前の定数の値を取り出します。
...name で指定される名前の定数の値を取り出します。
Module#const_defined? と違って Object を特別扱いすることはありません。
@param name 定数名。String か Symbol で指定します。
完全修飾名を指定しなかった場合はモジュー......m inherit false を指定するとスーパークラスや include したモジュールで
定義された定数は対象にはなりません。
@raise NameError 定数が定義されていないときに発生します。
//emlist[例][ruby]{
module Bar
BAR = 1
end
class Object
inclu......de 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 Name...