別のキーワード
ライブラリ
- ビルトイン (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
# ruby2 _ keywords(method _ name , . . . ) -> nil (12280.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 argument.......
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 versions
before 2.7,......the module responds to this method before calling
it. Also, be aware that if this method is removed, the behavior of the
method will change so that it does not pass through keywords.
//emlist[例][ruby]{
module Mod
def foo(meth, *args, &block)
send(:"do_#{meth}", *args, &block)
end
ruby2_... -
Module
# const _ source _ location(name , inherited = true) -> [String , Integer] (12214.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
# const _ missing(name) (6146.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
# deprecate _ constant(*name) -> self (6126.0) -
name で指定した定数を deprecate に設定します。 deprecate に設定した定数を参照すると警告メッセージが表示されます。
...セージが表示されます。
Ruby 2.7.2 から Warning[:deprecated] のデフォルト値が false に変更になったため、
デフォルトでは警告が表示されません。
コマンドラインオプション(詳細はd:spec/rubycmd#cmd_option参照)で、
「-w」か「-W2」な......い定数を指定した場合に発生します。
@return self を返します。
//emlist[例][ruby]{
FOO = 123
Object.deprecate_constant(:FOO) # => Object
FOO
# warning: constant ::FOO is deprecated
# => 123
Object.deprecate_constant(:BAR)
# NameError: constant Object::BAR not defined
//}... -
Module
# module _ function() -> nil (6126.0) -
メソッドをモジュール関数にします。
...します。
引数なしの時は 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......付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。
//emlist[例][ruby]{
module M
def foo
p "foo"
end
alias bar foo
module_function :foo, :bar
end
M.foo # => "foo"
M.bar # => "foo"
//}... -
Module
# module _ function(*name) -> Array (6126.0) -
メソッドをモジュール関数にします。
...します。
引数なしの時は 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......付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。
//emlist[例][ruby]{
module M
def foo
p "foo"
end
alias bar foo
module_function :foo, :bar
end
M.foo # => "foo"
M.bar # => "foo"
//}... -
Module
# module _ function(name) -> String | Symbol (6126.0) -
メソッドをモジュール関数にします。
...します。
引数なしの時は 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......付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。
//emlist[例][ruby]{
module M
def foo
p "foo"
end
alias bar foo
module_function :foo, :bar
end
M.foo # => "foo"
M.bar # => "foo"
//}... -
Module
# const _ added(name) -> () (6114.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 (6114.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
# const _ get(name , inherit = true) -> object (6114.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 や自分自身へ定義されて...