るりまサーチ

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

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dsa p
  5. dh p

ライブラリ

検索結果

Enumerable#zip(*lists) -> [[object]] (24258.0)

self と引数に渡した配列の各要素からなる配列の配列を生成して返します。 生成される配列の要素数は self の要素数と同じです。

...param lists 配列を指定します。配列でない場合は to_ary メソッドにより配列に変換します。
to_ary メソッドが無い場合は each を試します。

//emlist[例][ruby]{
p
(1..3).zip([4,5,6], [7,8,9])
# => [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

p
(1..2).zip...
...([:a,:b,:c], [:A,:B,:C,:D])
# => a, :A], [2, :b, :B

p
(1..5).zip([:a,:b,:c], [:A,:B,:C,:D])
# => [[1, :a, :A], [2, :b, :B],
# [3, :c, :C], [4, nil, :D], [5, nil, nil]]
//}

//emlist[例][ruby]{
p
[1,2,3].zip([4,5,6], [7,8,9]) {|ary|
p
ary
}
# => [1, 4, 7]
# [2, 5, 8]
# [3, 6, 9]
# ni...

Enumerable#zip(*lists) {|v1, v2, ...| ...} -> nil (24258.0)

self と引数に渡した配列の各要素からなる配列の配列を生成して返します。 生成される配列の要素数は self の要素数と同じです。

...param lists 配列を指定します。配列でない場合は to_ary メソッドにより配列に変換します。
to_ary メソッドが無い場合は each を試します。

//emlist[例][ruby]{
p
(1..3).zip([4,5,6], [7,8,9])
# => [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

p
(1..2).zip...
...([:a,:b,:c], [:A,:B,:C,:D])
# => a, :A], [2, :b, :B

p
(1..5).zip([:a,:b,:c], [:A,:B,:C,:D])
# => [[1, :a, :A], [2, :b, :B],
# [3, :c, :C], [4, nil, :D], [5, nil, nil]]
//}

//emlist[例][ruby]{
p
[1,2,3].zip([4,5,6], [7,8,9]) {|ary|
p
ary
}
# => [1, 4, 7]
# [2, 5, 8]
# [3, 6, 9]
# ni...

Enumerable#lazy -> Enumerator::Lazy (26.0)

自身を lazy な Enumerator に変換したものを返します。

...、配列ではな
くEnumeratorを返す) ように再定義されています。

* map/collect
* flat_map/collect_concat
* select/find_all
* reject
* grep
* take, take_while
* drop, drop_while
* zip (※一貫性のため、ブロックを渡さないケースのみlazy)
* cycle (※一...
...[例][ruby]{
def pythagorean_triples
(1..Float::INFINITY).lazy.flat_map {|z|
(1..z).flat_map {|x|
(x..z).select {|y|
x**2 + y**2 == z**2
}.map {|y|
[x, y, z]
}
}
}
end
# 最初の10個のピタゴラス数を表示する
p
pythagorean_triples.take(10).fo...
...rce # takeはlazyなので、forceが必要です
p
pythagorean_triples.first(10) # firstはeagerです
# 100より小さいピタゴラス数を表示する
p
pythagorean_triples.take_while { |*, z| z < 100 }.force
//}

@see Enumerator::Lazy...