83件ヒット
[1-83件を表示]
(0.186秒)
ライブラリ
- ビルトイン (83)
キーワード
-
each
_ with _ index (22) -
each
_ with _ object (22) - entries (11)
-
to
_ a (11) -
to
_ h (17)
検索結果
先頭5件
-
Enumerable
# each _ with _ index(*args) {|item , index| . . . } -> self (12522.0) -
要素とそのインデックスをブロックに渡して繰り返します。
...tor を返します。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。
@param args イテレータメソッド (each など) にそのまま渡されます。
//emli......st[例][ruby]{
[5, 10, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}
//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}
@......see Enumerator#with_index... -
Enumerable
# each _ with _ index(*args) -> Enumerator (12422.0) -
要素とそのインデックスをブロックに渡して繰り返します。
...tor を返します。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。
@param args イテレータメソッド (each など) にそのまま渡されます。
//emli......st[例][ruby]{
[5, 10, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}
//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}
@......see Enumerator#with_index... -
Enumerable
# each _ with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (12415.0) -
与えられた任意のオブジェクトと要素をブロックに渡し繰り返し、最初に与えられたオブジェクトを返します。
...返します。
ブロックを省略した場合は Enumerator を返します。
@param obj 任意のオブジェクトを指定します。
//emlist[例][ruby]{
evens = (1..10).each_with_object([]) {|i, a| a << i*2 }
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}
@see Enumerator#with_object... -
Enumerable
# entries(*args) -> [object] (12410.0) -
全ての要素を含む配列を返します。
...を返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
(1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
{ 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
require 'prime'
Prime.entries 10 #=> [2... -
Enumerable
# each _ with _ object(obj) -> Enumerator (12315.0) -
与えられた任意のオブジェクトと要素をブロックに渡し繰り返し、最初に与えられたオブジェクトを返します。
...返します。
ブロックを省略した場合は Enumerator を返します。
@param obj 任意のオブジェクトを指定します。
//emlist[例][ruby]{
evens = (1..10).each_with_object([]) {|i, a| a << i*2 }
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}
@see Enumerator#with_object... -
Enumerable
# to _ a(*args) -> [object] (9310.0) -
全ての要素を含む配列を返します。
...を返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
(1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
{ 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
require 'prime'
Prime.entries 10 #=> [2... -
Enumerable
# to _ h(*args) -> Hash (6316.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
...param args each の呼び出し時に引数として渡されます。
//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=>1, 2=>4, 3=>9, 4=>16, 5=>25}
//}... -
Enumerable
# to _ h(*args) { . . . } -> Hash (6316.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
...param args each の呼び出し時に引数として渡されます。
//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=>1, 2=>4, 3=>9, 4=>16, 5=>25}
//}... -
Enumerable
# to _ h(*args) -> Hash (6315.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
...self を [key, value] のペアの配列として解析した結果を Hash にして
返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}...