種類
- インスタンスメソッド (242)
- 特異メソッド (25)
- クラス (22)
ライブラリ
- ビルトイン (289)
クラス
- Array (44)
- Enumerator (14)
-
Enumerator
:: Lazy (77) - Object (44)
モジュール
- Enumerable (88)
キーワード
- Enumerator (11)
- Lazy (11)
-
chunk
_ while (11) - collect! (22)
-
collect
_ concat (11) -
enum
_ for (44) -
flat
_ map (11) - map! (22)
- new (25)
-
slice
_ after (22) -
slice
_ before (22) -
slice
_ when (11) - sum (22)
-
to
_ enum (44)
検索結果
先頭5件
-
Enumerator
:: Lazy # flat _ map {|item| . . . } -> Enumerator :: Lazy (11131.0) -
ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。
...["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}
ブロックの返した値 x は、以下の場合にのみ分解され、連結されます。
* x が配列であるか、to_ary メソッドを持つとき
* x が each および force メソッ......それ以外のときは、x は分解されず、そのままの値として使われます。
//emlist[][ruby]{
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force
#=> [{:a=>1}, {:b=>2}]
//}
@raise ArgumentError ブロックを指定しなかった場合に発生します。
@see Enumerable#flat_map... -
Array
# map! -> Enumerator (11126.0) -
各要素を順番にブロックに渡して評価し、その結果で要素を 置き換えます。
...ックが与えられなかった場合は、自身と map! から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
ary = [1, 2, 3]
ary.map! {|i| i * 3 }
p ary #=> [3, 6, 9]
ary = [1, 2, 3]
e = ary.map!
e.each{ 1 }
p ary #=> [1, 1, 1]
//}
@see Array#col... -
Array
# map! {|item| . . } -> self (11126.0) -
各要素を順番にブロックに渡して評価し、その結果で要素を 置き換えます。
...ックが与えられなかった場合は、自身と map! から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
ary = [1, 2, 3]
ary.map! {|i| i * 3 }
p ary #=> [3, 6, 9]
ary = [1, 2, 3]
e = ary.map!
e.each{ 1 }
p ary #=> [1, 1, 1]
//}
@see Array#col... -
Enumerator
. new(obj , method = :each , *args) -> Enumerator (8135.0) -
オブジェクト obj について、 each の代わりに method という 名前のメソッドを使って繰り返すオブジェクトを生成して返します。 args を指定すると、 method の呼び出し時に渡されます。
...オブジェクト obj について、 each の代わりに method という
名前のメソッドを使って繰り返すオブジェクトを生成して返します。
args を指定すると、 method の呼び出し時に渡されます。
@param obj イテレータメソッドのレシーバ......method イテレータメソッドの名前を表すシンボルまたは文字列
@param args イテレータメソッドの呼び出しに渡す任意個の引数
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new(str, :each_byte)
p enum.map {|b| '%02x' % b } # => ["78", "79", "7a"]
//}... -
Object
# enum _ for(method = :each , *args) -> Enumerator (8128.0) -
Enumerator.new(self, method, *args) を返します。
...数です。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
modu......_method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (8128.0) -
Enumerator.new(self, method, *args) を返します。
...数です。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
modu......_method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum... -
Object
# to _ enum(method = :each , *args) -> Enumerator (8128.0) -
Enumerator.new(self, method, *args) を返します。
...数です。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
modu......_method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum... -
Object
# to _ enum(method = :each , *args) {|*args| . . . } -> Enumerator (8128.0) -
Enumerator.new(self, method, *args) を返します。
...数です。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
modu......_method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (8122.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...gumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end
r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]
r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1,... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (8122.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...gumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end
r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]
r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1,...