るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

モジュール

キーワード

検索結果

Object#to_enum(method = :each, *args) -> Enumerator (29322.0)

Enumerator.new(self, method, *args) を返します。

...
E
numerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...//emlist[][ruby]{
str = "xyz"

e
num = 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...
...ef repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
e
nd
e
...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (29322.0)

Enumerator.new(self, method, *args) を返します。

...
E
numerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...//emlist[][ruby]{
str = "xyz"

e
num = 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...
...ef repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
e
nd
e
...

Enumerator#next_values -> Array (14287.0)

「次」のオブジェクトを配列で返します。

...ェクトを配列で返します。

E
numerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。

このメソッドは、
yield

yield nil
を区別するために使えます。

next メソッドによる外部列...
...IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

//emlist[例: next と next_values の違いを][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
yield nil
yield [1, 2]
e
nd
e
= o.to_enum
p e.next_...
...ues
p e.next_values
p e.next_values
p e.next_values
p e.next_values
e
= o.to_enum
p e.next
p e.next
p e.next
p e.next
p e.next

## yield args next_values next
# yield [] nil
# yield 1 [1] 1
# yield 1, 2 [1, 2] [1, 2]
# yie...

Enumerator#peek_values -> Array (14263.0)

Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。

...
E
numerator#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。

E
numerator#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり...
...eration 例外を発生します。

このメソッドは Enumerator#next_values と同様
yield

yield nil
を区別するために使えます。

//emlist[例][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
e
nd
e
= o.to_enum
p e.peek_values #=> []
e
.next
p e.peek_value...
...s #=> [1]
p e.peek_values #=> [1]
e
.next
p e.peek_values #=> [1, 2]
e
.next
p e.peek_values # raises StopIteration
//}

@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values...

Object#enum_for(method = :each, *args) -> Enumerator (14222.0)

Enumerator.new(self, method, *args) を返します。

...
E
numerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...//emlist[][ruby]{
str = "xyz"

e
num = 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...
...ef repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
e
nd
e
...

絞り込み条件を変える

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (14222.0)

Enumerator.new(self, method, *args) を返します。

...
E
numerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...//emlist[][ruby]{
str = "xyz"

e
num = 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...
...ef repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
e
nd
e
...

Enumerator (14020.0)

each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。

...each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。
また、外部イテレータとしても使えます。

E
numerable モジュールは、 Module#include 先のクラスが持つ
e
ach メソッドを元に様々なメソッドを提供し...
... Array#map は Array#each の繰り返しを元にして定義されます。
E
numerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。

E
numerator を生成するには Enumera...
...tor.newあるいは
Object#to_enum, Object#enum_for を利用します。また、一部の
イテレータはブロックを渡さずに呼び出すと繰り返しを実行する代わりに
e
numerator を生成して返します。

=== 注意
外部イテレータとしての機能は Fiber を...

Enumerable#compact -> Array (11115.0)

self から nil を取り除いた配列を生成して返します。

...self から nil を取り除いた配列を生成して返します。

//emlist[][ruby]{
def with_nils
yield 1
yield 2
yield nil
yield 3
e
nd

to_enum
(:with_nils).compact # => [1, 2, 3]
//}

@see Array#compact...