るりまサーチ

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

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

クラス

モジュール

キーワード

検索結果

<< < 1 2 >>

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (6275.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

t
o_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
t
o_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#grep(pattern) {|item| ... } -> Enumerator::Lazy (6272.0)

Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。

...くEnumerator::Lazy を返します。

//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).take(10).forc...
...e
# => ["111", "222", "333", "444", "555", "666", "777", "888", "999", "1111"]
//}

@see Enumerable#grep, Enumerable#grep_v, Enumerator::Lazy#grep_v...

Enumerator::Lazy#grep_v(pattern) {|item| ... } -> Enumerator::Lazy (6272.0)

Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。

...なくEnumerator::Lazy を返します。

//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep_v(/(\d).*\1/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/).take(15).forc...
...e
# => ["102", "103", "104", "105", "106", "107", "108", "109", "120", "123", "124", "125", "126", "127", "128"]
//}

@see Enumerable#grep_v, Enumerable#grep, Enumerator::Lazy#grep...

Enumerator::Lazy#grep(pattern) {|item| ... } -> Enumerator::Lazy (6266.0)

Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。

...くEnumerator::Lazy を返します。

//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).take(10).forc...

Enumerable#sum(init=0) -> object (113.0)

要素の合計を返します。

...が空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明示的...
...に指名すると数値以外のオブジェクトにも使えます。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定...
...義されている場合、Enumerable#sum は再定義を無視することがあります(例えばInteger#+)。

@see Array#sum...

絞り込み条件を変える

Enumerable#sum(init=0) {|e| expr } -> object (113.0)

要素の合計を返します。

...が空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明示的...
...に指名すると数値以外のオブジェクトにも使えます。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定...
...義されている場合、Enumerable#sum は再定義を無視することがあります(例えばInteger#+)。

@see Array#sum...
<< < 1 2 >>