るりまサーチ

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

別のキーワード

  1. _builtin |
  2. ipaddr |
  3. set |
  4. array |
  5. trueclass |

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Hash#to_h -> self | Hash (18253.0)

self を返します。Hash クラスのサブクラスから呼び出した場合は self を 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 {|key, value| block } -> Hash (18253.0)

self を返します。Hash クラスのサブクラスから呼び出した場合は self を 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...

Data#to_h {|member, value| block } -> Hash (18234.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Data.define(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Data.define(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anytow...

Struct#to_h {|member, value| block } -> Hash (18234.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anyt...

Hash#to_h -> self | Hash (18233.0)

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

...場合は
self を 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
//}...

絞り込み条件を変える

OpenStruct#to_h {|name, value| block } -> Hash (18228.0)

self を各要素の名前をキー(Symbol)、要素が値のハッシュに変換して返 します。

...結果をペアとして使います。

//emlist[例][ruby]{
require 'ostruct'
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
data.to_h # => {:country => "Australia", :capital => "Canberra" }
data.to_h {|name, value| [name.to_s, value.upcase] }
# => {"country"...

Data#to_h -> Hash (18134.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Data.define(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Data.define(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anytow...

Struct#to_h -> Hash (18134.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anyt...

Array#to_h -> Hash (18133.0)

self を [key, value] のペアの配列として解析した結果を Hash にして 返します。

...す。

//emlist[例][ruby]{
bar], [1, 2.to_h # => {:foo => :bar, 1 => 2}
//}

ブロックを指定すると配列の各要素でブロックを呼び出し、
その結果をペアとして使います。

//emlist[ブロック付きの例][ruby]{
["foo", "bar"].to_h {|s| [s.ord, s]} # => {102=>"f...

Array#to_h { block } -> Hash (18133.0)

self を [key, value] のペアの配列として解析した結果を Hash にして 返します。

...す。

//emlist[例][ruby]{
bar], [1, 2.to_h # => {:foo => :bar, 1 => 2}
//}

ブロックを指定すると配列の各要素でブロックを呼び出し、
その結果をペアとして使います。

//emlist[ブロック付きの例][ruby]{
["foo", "bar"].to_h {|s| [s.ord, s]} # => {102=>"f...

絞り込み条件を変える

Enumerable#to_h(*args) -> Hash (18133.0)

self を [key, value] のペアの配列として解析した結果を Hash にして 返します。

...

//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}

ブロックを指定すると各要素でブロックを呼び出し、
その結果をペアとして使います。

//emlist[ブロック付きの例][ruby]{
(1..5).to_h {|x| [x, x ** 2]} # => {1=...

Enumerable#to_h(*args) { ... } -> Hash (18133.0)

self を [key, value] のペアの配列として解析した結果を Hash にして 返します。

...

//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}

ブロックを指定すると各要素でブロックを呼び出し、
その結果をペアとして使います。

//emlist[ブロック付きの例][ruby]{
(1..5).to_h {|x| [x, x ** 2]} # => {1=...

OpenStruct#to_h -> { Symbol => object } (18128.0)

self を各要素の名前をキー(Symbol)、要素が値のハッシュに変換して返 します。

...結果をペアとして使います。

//emlist[例][ruby]{
require 'ostruct'
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
data.to_h # => {:country => "Australia", :capital => "Canberra" }
data.to_h {|name, value| [name.to_s, value.upcase] }
# => {"country"...

Array#collect {|item| ... } -> [object] (121.0)

各要素に対してブロックを評価した結果を全て含む配列を返します。

...してブロックを評価した結果を全て含む配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にする
p [1, 2, 3].map {|n| n * 3 } # => [3, 6, 9]
//}

@see Hash#to_h, Enumerable#collect, Enumerable#map...

Array#map {|item| ... } -> [object] (121.0)

各要素に対してブロックを評価した結果を全て含む配列を返します。

...してブロックを評価した結果を全て含む配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にする
p [1, 2, 3].map {|n| n * 3 } # => [3, 6, 9]
//}

@see Hash#to_h, Enumerable#collect, Enumerable#map...

絞り込み条件を変える

Enumerable#collect {|item| ... } -> [object] (121.0)

各要素に対してブロックを評価した結果を全て含む配列を返します。

...配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にした配列を返す
p (1..3).map {|n| n * 3 } # => [3, 6, 9]
p (1..3).collect { "cat" } # => ["cat", "cat", "cat"]
//}

@see Hash#to_h, Array#collect, Array#map...
<< 1 2 > >>