るりまサーチ

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

別のキーワード

  1. _builtin ==
  2. openssl ==
  3. rexml/document ==
  4. matrix ==
  5. == _builtin

クラス

キーワード

検索結果

KeyError#key -> object (21127.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#to_h {|key, value| block } -> Hash (127.0)

self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。

...を Hash オブジェクトに変換します。

//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true

class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # => {}
p my_hash.class # => MyHash
p my_hash.to_h.class # => Hash
//}

ブロックを...
...指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } # => {"A"=>65, "B"=>66}
//}

@see Enumerable#map...

Hash#to_h -> self | Hash (27.0)

self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。

...を Hash オブジェクトに変換します。

//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true

class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # => {}
p my_hash.class # => MyHash
p my_hash.to_h.class # => Hash
//}

ブロックを...
...指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } # => {"A"=>65, "B"=>66}
//}

@see Enumerable#map...

Symbol (26.0)

シンボルを表すクラス。シンボルは任意の文字列と一対一に対応するオブジェクトです。

...)。
そうでない文字列をシンボルにしたい場合は残りの表記か String#intern を使用してください。

==
= シンボルの実装と用途
==
== 実装
Rubyの内部実装では、メソッド名や変数名、定数名、クラス名など
の`名前'を整数で管理し...
...utable (変更不可)であり、同値ならば必ず同一です。

p "abc" == "abc" #=> true
p "abc".equal?("abc") #=> false
p :abc == :abc #=> true
p :abc.equal?(:abc) #=> true ←同値ならば同一

==
== 用途
実用面では、シンボルは文字の意味を明確にします。...
...`名前'を指し示す時など、
文字列そのものが必要なわけではない時に用います。


* ハッシュのキー { :key => "value" }
* アクセサの引数で渡すインスタンス変数名 attr_reader :name
* メソッド引数で渡すメソッド名 __send__ :to_s...