るりまサーチ

最速Rubyリファレンスマニュアル検索!
876件ヒット [101-200件を表示] (0.033秒)

別のキーワード

  1. openssl public_key
  2. _builtin each_key
  3. openssl public_key=
  4. dbm key
  5. socket pf_key

クラス

モジュール

キーワード

検索結果

<< < 1 2 3 4 ... > >>

Hash#transform_keys! -> Enumerator (6104.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...ransform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_...
...sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...

Hash#transform_keys!(hash) -> self (6104.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...ransform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_...
...sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_va...

Hash#transform_keys(hash) -> Hash (6104.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...mlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }...
...# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!...

Data#deconstruct_keys(array_of_names_or_nil) -> hash (6103.0)

self のメンバの名前と値の組を Hash で返します。

...//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)

distance = Measure.new(10, 'km')
distance.deconstruct_keys(nil) # => {:amount=>10, :unit=>"km"}
distance.deconstruct_keys([:amount]) # => {:amount=>10}
//}

このメソッドは以下のようにパターンマッチで利用され...
...st[例][ruby]{
Measure = Data.define(:amount, :unit)
distance = Measure.new(10, 'km')

case distance
in amount:, unit: 'km' # 裏側で #deconstruct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end
# "It is 10 kilometers away" が表示される...

Hash#keys -> [object] (6103.0)

全キーの配列を返します。

...全キーの配列を返します。

//emlist[例][ruby]{
h1 = { "a" => 100, 2 => ["some"], :c => "c" }
p h1.keys #=> ["a", 2, :c]
//}

@see Hash#values,Hash#to_a...

絞り込み条件を変える

Module#ruby2_keywords(method_name, ...) -> nil (6103.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.

...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
key
word splat. It marks the method such that if the method is called
with keyword arguments, the final hash arg...
...and that method call does not include explicit
key
words or a keyword splat, the final element is interpreted as
key
words. In other words, keywords will be passed through the method to
other methods.

This should only be used for methods that delegate keywords to another
method, and only for backward...
...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_keywords(:foo) if respond_to?(:ruby2_keywords, true)
end
//}...

Proc#ruby2_keywords -> proc (6103.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.

...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...
..., 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 another
method, and only for backwards...
...so, be aware that if this method is removed, the behavior of the
proc will change so that it does not pass through keywords.

//emlist[][ruby]{
module Mod
foo = ->(meth, *args, &block) do
send(:"do_#{meth}", *args, &block)
end
foo.ruby2_keywords if foo.respond_to?(:ruby2_keywords)
end
//}...

Thread#keys -> [Symbol] (6103.0)

スレッド固有データに関連づけられたキーの配列を返します。キーは Symbol で返されます。

...スレッド固有データに関連づけられたキーの配列を返します。キーは
Symbol で返されます。

th = Thread.current
th[:foo] = 'FOO'
th['bar'] = 'BAR'
p th.keys

#=> [:bar, :foo]...

Hash#include?(key) -> bool (3143.0)

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

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

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

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

@see Hash#value?...

Hash#member?(key) -> bool (3143.0)

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

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

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

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

@see Hash#value?...

絞り込み条件を変える

KeyError#receiver -> object (3009.0)

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

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

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

例:

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

Hash#fetch(key) {|key| ... } -> object (265.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...
key
に関連づけられた値を返します。該当するキーが登録されてい
ない時には、引数 default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetchはハッシュ自身にデフォ...
...も単に無視します(挙動に変化がありません)。

@param key 探索するキーを指定します。
@param default 該当するキーが登録されていない時の返り値を指定します。
@raise KeyError 引数defaultもブロックも与えられてない時、キー...
...ch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error") #=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key| #=> "two not exist"
"#{key} not exist" # warning: b...

Hash#delete(key) {|key| ... } -> object (252.0)

key に対応する要素を取り除きます。

...
key
に対応する要素を取り除きます。

@param key 取り除くキーを指定します。

@return 取り除かれた要素の値を返します。
key
に対応する要素が存在しない時には nil を返します。

与えられたブロックは key にマッ...
...チする要素がなかった時に評価され、その結果を返します。

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

p h.delete(:ab) #=> "some"
p h.delete(:ef) #=> nil
p h.delete(:ef){|key|"#{key} Nothing"} #=> "ef Nothing"

p h #=> {:cd=>"all"}
//}

@see Hash#delete_if...

Hash#fetch_values(key, ...) { |key| ... } -> [object] (212.0)

引数で指定されたキーに関連づけられた値の配列を返します。

...ックが与えられていない時は
Key
Error が発生します。

self にデフォルト値が設定されていても無視されます(挙動に変化がありません)。

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

@raise KeyError ブロックが与えられてない...
...=> "feline", "dog" => "canine", "cow" => "bovine" }

h.fetch_values("cow", "cat") # => ["bovine", "feline"]
h.fetch_values("cow", "bird") # raises KeyError
h.fetch_values("cow", "bird") { |k| k.upcase } # => ["bovine", "BIRD"]
//}

@see Hash#values_at, Hash#fetch...
<< < 1 2 3 4 ... > >>