るりまサーチ

最速Rubyリファレンスマニュアル検索!
154件ヒット [1-100件を表示] (0.054秒)
トップページ > クエリ:new[x] > クエリ:hash[x] > クエリ:to_hash[x]

別のキーワード

  1. _builtin hash
  2. _builtin to_hash
  3. dbm to_hash
  4. matrix hash
  5. hash []

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

NEWS for Ruby 2.0.0 (26090.0)

NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...NEWS for Ruby 2.0.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス...
...めのメソッドです
* 拡張: Enumerator.new サイズの遅延評価のための引数を一つ受け取るようになりました
* 新規クラス: Enumerator::Lazy 遅延列挙用のクラス

* ENV
* ENV.to_h は ENV.to_hash へのエイリアスです

* Fiber
* 非...
...ofiler.raw_data GCの加工していないプロファイルデータを返します

* Hash
* 追加: Hash#to_h 明示的に変換するメソッドです。Array#to_a に似ています
* 拡張: Hash#default_proc= default proc をクリアするために nil を渡せるようになり...

Object#to_hash -> Hash (24337.0)

オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。

説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要...
...すべての場面で代置可能であるような、
* ハッシュそのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_hash
{'as' => 24}
end
end

it = Foo.new
p({:as => 12}.merge(it)) #=> {"as"=>24, :as=>12}
//}...

CSV::Row#to_hash -> Hash (24321.0)

自身をシンプルなハッシュに変換します。

...プルなハッシュに変換します。

フィールドの順序は無視されます。
重複したフィールドは削除されます。

//emlist[例][ruby]{
require "csv"

row = CSV::Row.new(["header2", "header1", "header2"], [1, 2, 3])
row.to_hash # => {"header2"=>3, "header1"=>2}
//}...

Rake::TaskArguments#to_hash -> Hash (24321.0)

パラメータ名と対応する値を格納したハッシュを返します。

...納したハッシュを返します。

//emlist[][ruby]{
# Rakefile での記載例とする

task default: :test_rake_app
task :test_rake_app do
arguments = Rake::TaskArguments.new(["name1", "name2"], ["value1", "value2"])
arguments.to_hash # => {:name1=>"value1", :name2=>"value2"}
end
//}...

JSON::State#to_hash -> Hash (18310.0)

自身をハッシュに変換します。

...自身をハッシュに変換します。

//emlist[例][ruby]{
require "json"
require "pp"

json_state = JSON::State.new
pp json_state.to_h

# => {:indent=>"",
# :space=>"",
# :space_before=>"",
# :object_nl=>"",
# :array_nl=>"",
# :allow_nan=>false,
# :ascii_only=>false,...

絞り込み条件を変える

Hash#merge(*others) -> Hash (9156.0)

selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。

...値を使います。

othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。

@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結...
...1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>300}
h1.merge(h2, h3) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
h1...
...f to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash...

Hash#merge(*others) {|key, self_val, other_val| ... } -> Hash (9156.0)

selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。

...値を使います。

othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。

@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結...
...1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>300}
h1.merge(h2, h3) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
h1...
...f to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash...

Hash#merge(other) -> Hash (9156.0)

selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。

...r の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結...
..."b" => 254, "c" => 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=>300}
h1 # => {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a'...
...f to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash...

Hash#merge(other) {|key, self_val, other_val| ... } -> Hash (9156.0)

selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。

...r の値を使います。

otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結...
..."b" => 254, "c" => 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=>300}
h1 # => {"a"=>100, "b"=>200}
//}

//emlist[][ruby]{
foo = {1 => 'a'...
...f to_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end

h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}

# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}

@see Hash#update,Hash...

Hash.[](*key_and_value) -> Hash (9155.0)

新しいハッシュを生成します。 引数は必ず偶数個指定しなければなりません。奇数番目がキー、偶数番目が値になります。

...値になります。

このメソッドでは生成するハッシュにデフォルト値を指定することはできません。
Hash
.newを使うか、Hash#default=で後から指定してください。

@param key_and_value 生成するハッシュのキーと値の組です。必ず偶数...
...][ruby]{
ary = [1,"a", 2,"b", 3,["c"]]
p Hash[*ary] # => {1=>"a", 2=>"b", 3=>["c"]}
//}

(2) キーと値のペアの配列からハッシュへ

//emlist[][ruby]{
alist = [[1,"a"], [2,"b"], [3,["c"]]]
p alist.flatten(1) # => [1, "a", 2, "b", 3, ["c"]]
p Hash[*alist.flatten(1)] # => {1=>"a", 2=>"b...
...ls].transpose
p alist # => [[1, "a"], [2, "b"], [3, ["c"]]]
p Hash[alist] # => {1=>"a", 2=>"b", 3=>["c"]}
//}

(4) キーや値が配列の場合

//emlist[][ruby]{
alist = [[1,["a"]], [2,["b"]], [3,["c"]], [[4,5], ["a", "b"]]]
hash
= Hash[alist] # => {1=>["a"], 2=>["b"], 3=>["c"], [4, 5]=>["a", "b...

絞り込み条件を変える

Hash.[](other) -> Hash (9140.0)

新しいハッシュを生成します。 引数otherと同一のキーと値を持つ新たなハッシュを生成して返します。

...一のキーと値を持つ新たなハッシュを生成して返します。

引数otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

デフォルト値はコピーしません。生成されたハッシュのデフォルト値は ni...
...響します。

@param other 生成元となるハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。

//emlist[][ruby]{
h = {1 => "value"}
h.default = "none"

g = Hash[h]
p g #=> {1=>"value"}

p h[:no] #=> "none"
p g[:no] #=> nil

h[:add] = "some"
p...

Hash#replace(other) -> self (9090.0)

ハッシュの内容を other の内容で置き換えます。

...ります。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

self = other.to_hash.dup と同じです。

@param other ハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return sel...
...{2 => 'B', 3 => 'C'}

foo.replace(bar)
p foo #=> {2=>"B", 3=>"C"}

zoo = {}
zoo = bar.dup
p zoo #=> {2=>"B", 3=>"C"}

class Foo
def to_hash
{:japan => 'kyoto'}
end
end

h = Hash.new
h.replace(Foo.new) #暗黙の変換
p h #=> {:japan=>"kyoto"}
//}

@see Hash#dup,Hash#merge,Object#to_hash...
<< 1 2 > >>