るりまサーチ

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

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dsa p
  5. rsa p

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

KeyError#key -> object (21228.0)

KeyError の原因となったメソッド呼び出しのキーを返します。

...
Key
Error の原因となったメソッド呼び出しのキーを返します。

@raise ArgumentError キーが設定されていない時に発生します。

例:

h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p
e.message # => "key not found: \"gumbygumby...
...gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbyg..."
p
'gumby'*20 == e.key # => true
end...

Hash#key(val) -> object (18240.0)

値 val に対応するキーを返します。対応する要素が存在しない時には nil を返します。

...obsolete です。
使用すると警告メッセージが表示されます。

@param val 探索に用いる値を指定します。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all" , :ef => "all"}

p
h.key("some") #=> :ab
p
h.key("all") #=> :cd
p
h.key("at") #=> nil
//}

@see Hash#invert...
...キーが複数存在する場合、どのキーを返すかは不定です。


@param val 探索に用いる値を指定します。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all" , :ef => "all"}

p
h.key("some") #=> :ab
p
h.key("all") #=> :cd
p
h.key("at") #=> nil
//}

@see Hash#invert...

Proc#ruby2_keywords -> proc (9303.0)

Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the proc such that if the proc 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 proc to other methods.

...e proc as passing keywords through a normal argument splat. This
should only be called on procs that accept an argument splat (`*args`)
but not explicit keywords or a keyword splat. It marks the proc such
that if the proc is called with keyword arguments, the final hash
argument is marked with a sp...
...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 proc to other methods.

This should only be used for procs that delegate keywords to a...
...nother
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, check that the proc responds to this method before calling
it. Also...

Hash#has_key?(key) -> bool (6355.0)

ハッシュが key をキーとして持つ時真を返します。

...ハッシュが key をキーとして持つ時真を返します。

@param key 探索するキーを指定します。

//emlist[][ruby]{
p
({1 => "one"}.key?(1)) # => true
p
({1 => "one"}.key?(2)) # => false
//}

@see Hash#value?...

Hash#key?(key) -> bool (6355.0)

ハッシュが key をキーとして持つ時真を返します。

...ハッシュが key をキーとして持つ時真を返します。

@param key 探索するキーを指定します。

//emlist[][ruby]{
p
({1 => "one"}.key?(1)) # => true
p
({1 => "one"}.key?(2)) # => false
//}

@see Hash#value?...

絞り込み条件を変える

Hash#default_proc -> Proc | nil (6345.0)

ハッシュのデフォルト値を返す Proc オブジェクトを返します。 ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。

... Proc オブジェクトを返します。
ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。

//emlist[例][ruby]{
h = Hash.new {|hash, key| "The #{key} not exist in #{hash.inspect}"}
p
h.default #=> nil
p
block = h.default_proc #=> #<Pro...
...c:0x0x401a9ff4>
p
block.call({},:foo) #=> "The foo not exist in {}"

h = Hash.new("default")
p
h.default #=> "default"
p
h.default_proc #=> nil
//}

@see Hash#default...

Hash#each_key {|key| ... } -> self (6336.0)

ハッシュのキーを引数としてブロックを評価します。

...れた順です。
ブロック付きの場合selfを、
無しで呼ばれた場合Enumeratorを返します。

//emlist[例][ruby]{
{:a=>1, :b=>2}.each_key {|k| p k}
#=> :a
# :b

p
({:a=>1, :b=>2}.each_key) # => #<Enumerator: {:a=>1, :b=>2}:each_key>
//}

@see Hash#each_pair,Hash#each_value...

Hash#keep_if {|key, value| ... } -> self (6305.0)

キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。

...要素を self
に残します。

keep_if は常に self を返します。
select! はオブジェクトが変更された場合に self を、
されていない場合に nil を返します。

ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator オ...
...h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>

h1.select! { |k, v| k % 3 == 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h1.select! { |k, v| true } # => nil
h2.keep_if { |k, v| k % 3 == 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h2.keep_if { |k, v...

Hash#except(*keys) -> Hash (6303.0)

引数で指定された以外のキーとその値だけを含む Hash を返します。

...引数で指定された以外のキーとその値だけを含む Hash を返します。

引数に指定されていて Hash に存在しないキーは無視されます。

//emlist[][ruby]{
h = { a: 100, b: 200, c: 300 }
h.except(:a) # => {:b=>200, :c=>300}
//}

@see Hash#slice, ENV.except...

Proc#parameters(lambda: nil) -> [object] (6239.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

P
roc オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...必須の引数
: :opt
デフォルト値が指定されたオプショナルな引数
: :rest
* で指定された残りすべての引数
: :keyreq
必須のキーワード引数
: :key
デフォルト値が指定されたオプショナルなキーワード引数
: :keyrest
** で指定さ...
...

@param lambda true なら lambda として扱ったとき、false なら lambda ではない Proc として
扱ったときの引数の情報を返します。

//emlist[例][ruby]{
p
rc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
p
rc.parameters #=> x], [:opt, :y], [:...

絞り込み条件を変える

Hash#each_key -> Enumerator (6236.0)

ハッシュのキーを引数としてブロックを評価します。

...れた順です。
ブロック付きの場合selfを、
無しで呼ばれた場合Enumeratorを返します。

//emlist[例][ruby]{
{:a=>1, :b=>2}.each_key {|k| p k}
#=> :a
# :b

p
({:a=>1, :b=>2}.each_key) # => #<Enumerator: {:a=>1, :b=>2}:each_key>
//}

@see Hash#each_pair,Hash#each_value...

Method#parameters -> [object] (6215.0)

Method オブジェクトの引数の情報を返します。

...必須の引数
: :opt
デフォルト値が指定されたオプショナルな引数
: :rest
* で指定された残りすべての引数
: :keyreq
必須のキーワード引数
: :key
デフォルト値が指定されたオプショナルなキーワード引数
: :keyrest
** で指定さ...
...t[例][ruby]{
m = Class.new{define_method(:m){|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}}.instance_method(:m)
m.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
File.method(:symlink).parameters #=> req
//}

@see Proc#parameters...
...st[例][ruby]{
m = Class.new{define_method(:m){|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}}.instance_method(:m)
m.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
File.method(:symlink).parameters #=> req
//}

@see Proc#parameters...

Proc#parameters -> [object] (6215.0)

Proc オブジェクトの引数の情報を返します。

...Proc オブジェクトの引数の情報を返します。

P
roc オブジェクトが引数を取らなければ空の配列を返します。引数を取る場合は、配列の配列を返し、
各配列の要素は引数の種類に対応した以下のような Symbol と、引数名を表す...
...必須の引数
: :opt
デフォルト値が指定されたオプショナルな引数
: :rest
* で指定された残りすべての引数
: :keyreq
必須のキーワード引数
: :key
デフォルト値が指定されたオプショナルなキーワード引数
: :keyrest
** で指定さ...
...ck
& で指定されたブロック引数


//emlist[例][ruby]{
p
rc = lambda{|x, y=42, *other, k_x:, k_y: 42, **k_other, &b|}
p
rc.parameters #=> x], [:opt, :y], [:rest, :other], [:keyreq, :k_x], [:key, :k_y], [:keyrest, :k_other], [:block, :b
//}


@see Method#parameters, UnboundMethod#parameters...
<< 1 2 3 ... > >>