ライブラリ
クラス
-
ARGF
. class (252) - Array (684)
- Date (72)
- Dir (38)
- Enumerator (187)
-
Enumerator
:: ArithmeticSequence (98) -
Enumerator
:: Chain (35) -
Enumerator
:: Lazy (417) -
Enumerator
:: Yielder (30) -
Gem
:: SourceIndex (24) - Hash (344)
- IO (300)
- Integer (72)
- Matrix (196)
- Numeric (93)
- Object (78)
- OpenStruct (24)
- Pathname (126)
- Prime (24)
-
Prime
:: PseudoPrimeGenerator (84) -
Psych
:: Nodes :: Node (24) -
REXML
:: Parent (96) - Range (97)
- StopIteration (12)
- String (208)
- StringIO (176)
- Struct (86)
- Vector (160)
-
Zlib
:: GzipReader (72)
モジュール
- Enumerable (789)
- TSort (66)
キーワード
- % (14)
- + (7)
- << (12)
- == (7)
- ascend (24)
- begin (7)
- bsearch (48)
-
bsearch
_ index (20) - bytes (42)
- chain (7)
- chars (42)
- chunk (36)
-
chunk
_ while (21) - codepoints (42)
- collect (108)
- collect! (52)
- collect2 (24)
-
collect
_ concat (36) - combination (24)
- compact (4)
- cycle (48)
-
delete
_ if (72) - descend (24)
- detect (24)
- downto (48)
- drop (12)
-
drop
_ while (60) - each (508)
- each2 (24)
-
each
_ byte (120) -
each
_ char (96) -
each
_ child (62) -
each
_ codepoint (96) -
each
_ cons (24) -
each
_ entry (30) -
each
_ grapheme _ cluster (16) -
each
_ index (48) -
each
_ key (24) -
each
_ line (216) -
each
_ pair (72) -
each
_ slice (24) -
each
_ strongly _ connected _ component (22) -
each
_ strongly _ connected _ component _ from (22) -
each
_ value (24) -
each
_ with _ index (72) -
each
_ with _ object (24) - eager (6)
- end (7)
-
enum
_ for (48) -
exclude
_ end? (7) - feed (12)
- filter (63)
- filter! (28)
-
filter
_ map (18) - find (48)
-
find
_ all (36) -
find
_ index (108) - first (14)
-
flat
_ map (36) - force (12)
- grep (12)
-
grep
_ v (10) -
group
_ by (24) - gsub (48)
- gsub! (48)
- hash (7)
- index (72)
- inspect (14)
-
keep
_ if (48) - last (14)
- lazy (24)
- lines (98)
- map (108)
- map! (52)
- map2 (12)
-
max
_ by (48) -
min
_ by (48) -
minmax
_ by (24) - next (12)
-
next
_ values (12) - partition (24)
- peek (12)
-
peek
_ values (12) - permutation (24)
- reject (84)
- reject! (48)
-
repeated
_ combination (24) -
repeated
_ permutation (24) - result (12)
-
reverse
_ each (52) - rewind (31)
- rindex (36)
- select (108)
- select! (48)
- size (26)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
sort
_ by (24) -
sort
_ by! (24) - step (155)
- take (12)
-
take
_ while (72) - then (14)
- times (24)
-
to
_ enum (48) -
to
_ proc (6) -
transform
_ keys (20) -
transform
_ keys! (20) -
transform
_ values (18) -
transform
_ values! (18) -
tsort
_ each (22) - uniq (18)
- upto (48)
-
with
_ index (60) -
with
_ object (48) - yield (12)
-
yield
_ self (16) - zip (24)
検索結果
先頭5件
-
Enumerator
# with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (21020.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
...かった場合は、上で説明した繰り返しを実行し、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_obje... -
Enumerator
# with _ index(offset = 0) {|(*args) , idx| . . . } -> object (21014.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...ブロックを指定した場合の戻り値は生成時に指定したレシーバ自身です。
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]
require......ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその... -
Enumerator
# size -> Integer | Float :: INFINITY | nil (21013.0) -
self の要素数を返します。
...self の要素数を返します。
要素数が無限の場合は Float::INFINITY を返します。
Enumerator.new に Proc オブジェクトを指定していた場合はその
実行結果を返します。呼び出した時に要素数が不明であった場合は nil を返し
ます。
/....../emlist[例][ruby]{
(1..100).to_a.permutation(4).size # => 94109400
loop.size # => Float::INFINITY
(1..100).drop_while.size # => nil
//}
@see Enumerator.new... -
Enumerator
# each -> self (21008.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"... -
Enumerator
# each { . . . } -> object (21008.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"... -
Enumerator
# each(*args) { . . . } -> object (21008.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"... -
Enumerator
# next -> object (21007.0) -
「次」のオブジェクトを返します。
...用を
伴っている場合には影響があり得ます。
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#rewind
//emlist[例1][ruby]{
str = "xyz"
enum = str.each_byte
str.bytesize.times do
puts enum.next
end
# => 120
# 121
# 122... -
Enumerator
# rewind -> self (21007.0) -
列挙状態を巻き戻します。
...が rewind メソッドを持つとき(respond_to?(:rewind) に
真を返すとき) は、その rewind メソッドを呼び出します。
@see Enumerator#next
//emlist[例][ruby]{
str = "xyz"
enum = str.each_byte
p enum.next # => 120
p enum.next # => 121
enum.rewind
p enum.next # => 120
//}... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (3151.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...Object#to_enum と同じですが、Enumerator::Lazy を返します。
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)
ra......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 のときは Enumerator に、
# もとが Lazy のときは Lazy になる
//}... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (3151.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...Object#to_enum と同じですが、Enumerator::Lazy を返します。
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)
ra......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 のときは Enumerator に、
# もとが Lazy のときは Lazy になる
//}...