るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

モジュール

キーワード

検索結果

Enumerable#each_with_index(*args) -> Enumerator (18321.0)

要素とそのインデックスをブロックに渡して繰り返します。

...受け取りますが、
each_with_index
は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][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) {|item, index| ... } -> self (18321.0)

要素とそのインデックスをブロックに渡して繰り返します。

...受け取りますが、
each_with_index
は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][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#to_h(*args) -> Hash (207.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}
//}...
...例][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...

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

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

...例][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...

Enumerator#with_index(offset = 0) {|(*args), idx| ... } -> object (207.0)

生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。

...にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index
は受け取りません (引数はイテレータメソッドにそのまま渡されます)。...

絞り込み条件を変える

Matrix#each(which = :all) -> Enumerator (161.0)

行列の各要素を引数としてブロックを呼び出します。

...ができます。
*
:all - すべての要素(デフォルト)
*
:diagonal - 対角要素
*
:off_diagonal 対角要素以外
*
:lower 対角成分とそれより下側の部分
*
:upper対角成分とそれより上側の部分
*
:strict_lower 対角成分の下側
*
:strict_upper 対...
...uby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each { |e| puts e }
# => prints the numbers 1 to 4
Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
//}

@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each_with_index, Matrix#map...

Matrix#each(which = :all) {|e| ... } -> self (161.0)

行列の各要素を引数としてブロックを呼び出します。

...ができます。
*
:all - すべての要素(デフォルト)
*
:diagonal - 対角要素
*
:off_diagonal 対角要素以外
*
:lower 対角成分とそれより下側の部分
*
:upper対角成分とそれより上側の部分
*
:strict_lower 対角成分の下側
*
:strict_upper 対...
...uby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each { |e| puts e }
# => prints the numbers 1 to 4
Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
//}

@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each_with_index, Matrix#map...