種類
- インスタンスメソッド (192)
- 文書 (50)
- 変数 (12)
- 定数 (12)
- クラス (12)
クラス
- IO (144)
- Object (12)
-
Zlib
:: GzipReader (48)
モジュール
- Kernel (12)
キーワード
-
$ stdin (12) - DATA (12)
- IO (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 3
. 0 . 0 (5) - each (96)
-
ruby 1
. 6 feature (12) - 制御構造 (12)
検索結果
先頭5件
-
Zlib
:: GzipReader # each _ line(rs = $ / ) -> Enumerator (15130.0) -
IO クラスの同名メソッドIO#each, IO#each_lineと同じです。
...IO クラスの同名メソッドIO#each, IO#each_lineと同じです。
但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。
gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルの......* EOF (圧縮データの最後) を越えて読み込み要求を受けた時。
すなわち Zlib::GzipReader#read,
Zlib::GzipReader#gets メソッド等が nil を返す時。
* EOF まで読み込んだ後、Zlib::GzipFile#close メソッドが
呼び出された時。
* EOF......照
require 'zlib'
=begin
# hoge.gz がない場合は下記で作成できる。
Zlib::GzipWriter.open('hoge.gz') { |gz|
gz.puts 'hoge'
gz.puts 'fuga'
}
=end
Zlib::GzipReader.open('hoge.gz') { |gz|
gz.each { |line|
puts line
}
}
@see IO#each, IO#each_line... -
Zlib
:: GzipReader # each _ line(rs = $ / ) {|line| . . . } -> self (15130.0) -
IO クラスの同名メソッドIO#each, IO#each_lineと同じです。
...IO クラスの同名メソッドIO#each, IO#each_lineと同じです。
但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。
gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルの......* EOF (圧縮データの最後) を越えて読み込み要求を受けた時。
すなわち Zlib::GzipReader#read,
Zlib::GzipReader#gets メソッド等が nil を返す時。
* EOF まで読み込んだ後、Zlib::GzipFile#close メソッドが
呼び出された時。
* EOF......照
require 'zlib'
=begin
# hoge.gz がない場合は下記で作成できる。
Zlib::GzipWriter.open('hoge.gz') { |gz|
gz.puts 'hoge'
gz.puts 'fuga'
}
=end
Zlib::GzipReader.open('hoge.gz') { |gz|
gz.each { |line|
puts line
}
}
@see IO#each, IO#each_line... -
IO
# each _ line(limit) -> Enumerator (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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 (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
IO
# each _ line(limit , chomp: false) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
IO
# each _ line(rs = $ / ) -> Enumerator (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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 = $ / ) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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 (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
IO
# each _ line(rs = $ / , chomp: false) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
IO
# each _ line(rs , limit) -> Enumerator (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...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 (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
IO
# each _ line(rs , limit , chomp: false) {|line| . . . } -> self (15112.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}
@see $/, IO#gets... -
Object
:: DATA -> File (54.0) -
スクリプトの __END__ プログラムの終り以降をアクセスする File オブジェクト。
...イル ($0) を指します。
=== 例1
print DATA.gets # => 故人西辞黄鶴楼
print DATA.gets # => 烟花三月下揚州
print DATA.gets # => 孤帆遠影碧空尽
print DATA.gets # => 唯見長江天際流
DATA.gets # => nil
__END__
故人西辞黄鶴楼......唯見長江天際流
=== 例2
sum = 0
DATA.each_line do |line|
sum += line.to_i
end
DATA.rewind
p DATA.gets # => "sum = 0¥n"
__END__
17
19
23
29
31
=== 例3
DATA.gets # => uninitialized constant DATA (NameError)
=== 例4......ファイル library.rb と app.rb の内容が以下であったとします。
library.rb:
print DATA.gets
__END__
data from library
app.rb:
require 'library.rb'
__END__
data from app
このときシェルから次を実行すると
$ ruby app.rb
結果は以...