498件ヒット
[401-498件を表示]
(0.088秒)
クラス
- Array (48)
-
Enumerator
:: Lazy (124) - Hash (14)
- Object (48)
- Set (24)
モジュール
- Enumerable (240)
キーワード
-
chunk
_ while (12) - collect (60)
- collect! (12)
-
collect
_ concat (36) -
enum
_ for (48) -
filter
_ map (18) -
flat
_ map (36) - grep (12)
-
grep
_ v (10) - lazy (12)
- map! (12)
-
slice
_ after (24) -
slice
_ before (24) -
slice
_ when (12) -
sort
_ by (24) - sum (24)
-
to
_ enum (48) -
to
_ h (14)
検索結果
先頭5件
-
Enumerator
:: Lazy # to _ enum(method = :each , *args) -> Enumerator :: Lazy (19.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...ように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0......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, 4, 4, 9]
# Lazy#to_enum のおかげで、repeat の返り値... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (19.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...ように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0......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, 4, 4, 9]
# Lazy#to_enum のおかげで、repeat の返り値... -
Set
# collect! {|o| . . . } -> self (14.0) -
集合の各要素についてブロックを評価し、その結果で元の集合を置き換えます。
...集合の各要素についてブロックを評価し、その結果で元の集合を置き換えます。
//emlist[][ruby]{
require 'set'
set = Set['hello', 'world']
set.map! {|str| str.capitalize}
p set # => #<Set: {"Hello", "World"}>
//}
@see Enumerable#collect......集合の各要素についてブロックを評価し、その結果で元の集合を置き換えます。
//emlist[][ruby]{
set = Set['hello', 'world']
set.map! {|str| str.capitalize}
p set # => #<Set: {"Hello", "World"}>
//}
@see Enumerable#collect... -
Hash
# to _ h -> self | Hash (13.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...sh
//}
ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } # => {"A"=>65, "B"=>66}
//}
@see Enumerable#map... -
Hash
# to _ h {|key , value| block } -> Hash (13.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...sh
//}
ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } # => {"A"=>65, "B"=>66}
//}
@see Enumerable#map... -
Object
# enum _ for(method = :each , *args) -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...= 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]{
module Enumerable
def repeat(n)
raise ArgumentEr... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...= 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]{
module Enumerable
def repeat(n)
raise ArgumentEr... -
Object
# to _ enum(method = :each , *args) -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...= 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]{
module Enumerable
def repeat(n)
raise ArgumentEr... -
Object
# to _ enum(method = :each , *args) {|*args| . . . } -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...= 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]{
module Enumerable
def repeat(n)
raise ArgumentEr...