るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

String#each_line(rs = $/) -> Enumerator (26409.0)

文字列中の各行に対して繰り返します。 行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。 各 line には区切りの文字列も含みます。

..."aa\nbb\ncc\n".each_line do |line|
p line
end
# => "aa\n"
# => "bb\n"
# => "cc\n"

p "aa\nbb\ncc\n".lines.to_a # => ["aa\n", "bb\n", "cc\n"]
p "aa\n".lines.to_a # => ["aa\n"]
p "".lines.to_a # => []

s = "aa\nbb\ncc\n"
p s.lines("\n").to_a #=> ["aa\n", "bb\n"...
..., "cc\n"]
p s.lines("bb").to_a #=> ["aa\nbb", "\ncc\n"]
//}

@see String#lines...

String#each_line(rs = $/, chomp: false) -> Enumerator (26409.0)

文字列中の各行に対して繰り返します。 行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。 各 line には区切りの文字列も含みます。

..."aa\nbb\ncc\n".each_line do |line|
p line
end
# => "aa\n"
# => "bb\n"
# => "cc\n"

p "aa\nbb\ncc\n".lines.to_a # => ["aa\n", "bb\n", "cc\n"]
p "aa\n".lines.to_a # => ["aa\n"]
p "".lines.to_a # => []

s = "aa\nbb\ncc\n"
p s.lines("\n").to_a #=> ["aa\n", "bb\n"...
..., "cc\n"]
p s.lines("bb").to_a #=> ["aa\nbb", "\ncc\n"]
//}

@see String#lines...

ARGF.class#each_line(rs = $/) -> Enumerator (23417.0)

ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。

...読み込み、それを引数として与えら
れたブロックを実行します。

ブロックが与えられなかった場合は、Enumerator オブジェクトを生成し
て返します。

このメソッドはスクリプトに指定した引数(Object::ARGV を参照) をファ
...
...フモード)。

@param limit 各行の最大の読み込みバイト数

例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示

ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end

@see IO#each, IO#each_line...

ARGF.class#each_line(rs = $/, limit) -> Enumerator (23417.0)

ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。

...読み込み、それを引数として与えら
れたブロックを実行します。

ブロックが与えられなかった場合は、Enumerator オブジェクトを生成し
て返します。

このメソッドはスクリプトに指定した引数(Object::ARGV を参照) をファ
...
...フモード)。

@param limit 各行の最大の読み込みバイト数

例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示

ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end

@see IO#each, IO#each_line...

IO#each_line(limit) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

絞り込み条件を変える

IO#each_line(limit, chomp: false) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: cho...

IO#each_line(rs = $/) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(rs = $/, chomp: false) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: cho...

IO#each_line(rs, limit) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(rs, limit, chomp: false) -> Enumerator (23407.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数を...
...e", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: And so on..."
//}
//emlist[例: 行の区切りに半角カ...
..."This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: cho...

絞り込み条件を変える

Enumerator#next -> object (11219.0)

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

...じて「次」のオブジェクトを返し、列挙状態を1つ分進めます。
列挙が既に最後へ到達している場合は、
StopIteration 例外を発生します。このとき列挙状態は変化しません。
つまりもう一度 next を呼ぶと再び例外が発生します...
...響を与えません。
ただし、 IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

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

//emlist[例1][ruby]{
str = "...
...=> 120
# 121
# 122
//}

//emlist[例2][ruby]{
str = "xyz"
enum = str.each_byte

begin
puts enum.next while true
rescue StopIteration
puts "iteration reached at end"
end
# => 120
# 121
# 122
# iteration reached at end
puts enum.next
#=> 再度 StopIterat...

Enumerator#next_values -> Array (11207.0)

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

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

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

このメソッドは、
yield

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

next メソッ...
...ドによる外部列挙の状態は他のイテレータメソッドによる
内部列挙には影響を与えません。
ただし、 IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

//emlist[例: next と next_v...
...[1] 1
# yield 1, 2 [1, 2] [1, 2]
# yield nil [nil] nil
# yield [1, 2] [[1, 2]] [1, 2]
//}

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

Enumerator::Yielder#to_proc -> Proc (11207.0)

Enumerator.new で使うメソッドです。

...Enumerator.new で使うメソッドです。

引数を Enumerator::Yielder#yield に渡す Proc を返します。
これは Enumerator::Yielder オブジェクトを他のメソッドにブロック引数と
して直接渡すために使えます。

//emlist[例][ruby]{
text = <<-END
Hello
...
...んにちは
END

enum = Enumerator.new do |y|
text.each_line(&y)
end

enum.each do |line|
p line
end
# => "Hello\n"
# "こんにちは\n"
//}...

ARGF.class#lines(limit) -> Enumerator (8323.0)

このメソッドは obsolete です。 代わりに ARGF.class#each_line を使用してください。 使用すると警告メッセージが表示されます。

...このメソッドは obsolete です。
代わりに ARGF.class#each_line を使用してください。
使用すると警告メッセージが表示されます。

@see $/, ARGF.class#each_line...
<< 1 2 > >>