487件ヒット
[1-100件を表示]
(0.135秒)
別のキーワード
ライブラリ
- ビルトイン (487)
キーワード
- chunk (12)
-
chunk
_ while (12) - count (36)
-
each
_ cons (24) -
each
_ entry (24) -
each
_ slice (24) -
each
_ with _ index (24) -
each
_ with _ object (24) - entries (12)
- first (24)
- inject (36)
- reduce (36)
-
reverse
_ each (24) -
slice
_ after (24) -
slice
_ before (24) -
slice
_ when (12) - sum (24)
- take (12)
-
take
_ while (24) -
to
_ a (12) -
to
_ h (19) - zip (24)
検索結果
先頭5件
-
Enumerable
# each _ with _ index(*args) -> Enumerator (12252.0) -
要素とそのインデックスをブロックに渡して繰り返します。
...返すような
Enumerator を返します。
Enumerator#with_index は offset 引数を受け取りますが、
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 (12252.0) -
要素とそのインデックスをブロックに渡して繰り返します。
...返すような
Enumerator を返します。
Enumerator#with_index は offset 引数を受け取りますが、
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 _ entry -> Enumerator (12228.0) -
ブロックを各要素に一度ずつ適用します。
...配列として渡されます。
//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}
ブロックを省略した場合は Enumerator が返されます。
@see Enumerable#slice_before... -
Enumerable
# each _ entry {|obj| block} -> self (12228.0) -
ブロックを各要素に一度ずつ適用します。
...配列として渡されます。
//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield 1
yield 1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}
ブロックを省略した場合は Enumerator が返されます。
@see Enumerable#slice_before... -
Enumerable
# each _ with _ object(obj) -> Enumerator (12222.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
# each _ with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (12222.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
# slice _ after(pattern) -> Enumerator (6238.0) -
パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し ます。
...素、もしくはブロックが真を返した要素を末尾の要素
としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し
ます。
パターンを渡した場合は各要素に対し === が呼び出され、 それが真になった
ところをチャン......事もできます。
//emlist[例][ruby]{
enum.slice_after(pattern).each { |ary|
# ...
}
enum.slice_after { |elt| bool }.each { |ary|
# ...
}
//}
//emlist[例][ruby]{
# 偶数要素をチャンクの末尾と見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:even?).to_a
# => [[0], [2], [4], [1,......見なす
[0,2,4,1,2,4,5,3,1,4,2].slice_after(&:odd?).to_a
# => [[0, 2, 4, 1], [2, 4, 5], [3], [1], [4, 2]]
# バックスラッシュで終わる行を継続
lines = ["foo\n", "bar\\\n", "baz\n", "\n", "qux\n"]
e = lines.slice_after(/(?<!\\)\n\z/)
p e.to_a
#=> [["foo\n"], ["bar\\\n", "baz\n"], ["\... -
Enumerable
# each _ cons(n) -> Enumerator (6228.0) -
要素を重複ありで n 要素ずつに区切り、 ブロックに渡して繰り返します。
...素ずつ繰り返す Enumerator を返します。
@param n ブロックに渡す要素の数です。正の整数を与えます。
要素数より大きな数を与えると、ブロックは一度も実行されません。
//emlist[例][ruby]{
(1..10).each_cons(3){|v| p v }
# => [1,......2, 3]
# [2, 3, 4]
# [3, 4, 5]
# [4, 5, 6]
# [5, 6, 7]
# [6, 7, 8]
# [7, 8, 9]
# [8, 9, 10]
//}
@see Enumerable#each_slice... -
Enumerable
# each _ cons(n) {|list| . . . } -> nil (6228.0) -
要素を重複ありで n 要素ずつに区切り、 ブロックに渡して繰り返します。
...素ずつ繰り返す Enumerator を返します。
@param n ブロックに渡す要素の数です。正の整数を与えます。
要素数より大きな数を与えると、ブロックは一度も実行されません。
//emlist[例][ruby]{
(1..10).each_cons(3){|v| p v }
# => [1,......2, 3]
# [2, 3, 4]
# [3, 4, 5]
# [4, 5, 6]
# [5, 6, 7]
# [6, 7, 8]
# [7, 8, 9]
# [8, 9, 10]
//}
@see Enumerable#each_slice...