るりまサーチ

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

別のキーワード

  1. kernel $rs
  2. kernel $fs
  3. kernel $ors
  4. kernel $defs
  5. kernel $ofs

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

IO#gets(rs = $/) -> String | nil (18228.0)

一行読み込んで、読み込みに成功した時にはその文字列を返します。 EOF に到達した時には nil を返します。

...F に到達した時には nil を返します。

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

読み込んだ文字列を変数 $_ にセットします。
IO#readline との違いは EOF での振る舞いのみです。

limit で最大の読み込みバイト数を指定し...
...ていなければ発生します。

f = File.new("oneline_file")
f.gets #=> "This is line one\n"
$
_ #=> "This is line one\n"
f.gets #=> nil
$
_ #=> nil

@see $/, IO#readline...

IO#gets(rs = $/, chomp: false) -> String | nil (18228.0)

一行読み込んで、読み込みに成功した時にはその文字列を返します。 EOF に到達した時には nil を返します。

...F に到達した時には nil を返します。

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

読み込んだ文字列を変数 $_ にセットします。
IO#readline との違いは EOF での振る舞いのみです。

limit で最大の読み込みバイト数を指定し...
...ていなければ発生します。

f = File.new("oneline_file")
f.gets #=> "This is line one\n"
$
_ #=> "This is line one\n"
f.gets #=> nil
$
_ #=> nil

@see $/, IO#readline...

IO#readlines(rs = $/, chomp: false) -> [String] (137.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...uby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File
.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File
.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File
.open("testfile") { |f| p f.readlin...
...chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File
.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File
.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO#each(rs = $/, chomp: false) -> Enumerator (125.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...区切りに半角カンマ、最大読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "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 i...
...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(rs = $/, chomp: false) {|line| ... } -> self (125.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...区切りに半角カンマ、最大読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "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 i...
...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) -> Enumerator (125.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...区切りに半角カンマ、最大読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "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 i...
...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 (125.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...区切りに半角カンマ、最大読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "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 i...
...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#readline(rs = $/) -> String (125.0)

一行読み込んで、読み込みに成功した時にはその文字列を返します。 EOF に到達した時には EOFError が発生します。

...EOFError が発生します。

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

読み込んだ文字列を変数 $_ にセットします。IO#gets との違いは EOF での振る舞いのみです。

limit で最大読み込みバイト数を指定します。ただしマルチ...
...ていなければ発生します。

f = File.new("oneline_file")
f.readline #=> "This is line one\n"
$
_ #=> "This is line one\n"
f.readline #=> EOFError
$
_ #=> nil

@see $/, IO#gets...

IO#readline(rs = $/, chomp: false) -> String (125.0)

一行読み込んで、読み込みに成功した時にはその文字列を返します。 EOF に到達した時には EOFError が発生します。

...EOFError が発生します。

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

読み込んだ文字列を変数 $_ にセットします。IO#gets との違いは EOF での振る舞いのみです。

limit で最大読み込みバイト数を指定します。ただしマルチ...
...ていなければ発生します。

f = File.new("oneline_file")
f.readline #=> "This is line one\n"
$
_ #=> "This is line one\n"
f.readline #=> EOFError
$
_ #=> nil

@see $/, IO#gets...

IO#readlines(rs = $/) -> [String] (125.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...uby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File
.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File
.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File
.open("testfile") { |f| p f.readlin...
...es(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}


@see $/, IO#gets...

絞り込み条件を変える

IO#each(rs = $/) -> Enumerator (119.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...stfile", "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(rs = $/) {|line| ... } -> self (119.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...stfile", "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 = $/) -> Enumerator (119.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...stfile", "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 (119.0)

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

...ンされていなければ発生します。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "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,\...
...stfile", "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...

Zlib::GzipReader#readline(rs = $/) -> String (113.0)

IO クラスの同名メソッドIO#readlineと同じです。

...スの同名メソッドIO#readlineと同じです。

但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。

gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルのフッターには圧...
...た場合は
Zlib::GzipFile::NoFooter, Zlib::GzipFile::CRCError,
Zlib::GzipFile::LengthError 例外を発生させます。

* EOF (圧縮データの最後) を越えて読み込み要求を受けた時。
すなわち Zlib::GzipReader#read,
Zlib::GzipReader#gets メソッド等が nil...
...を返す時。
* EOF まで読み込んだ後、Zlib::GzipFile#close メソッドが
呼び出された時。
* EOF まで読み込んだ後、Zlib::GzipReader#unused メソッドが
呼び出された時。

@param rs 行の区切りを文字列で指定します。

@raise EOFError E...

絞り込み条件を変える

ARGF.class#getbyte -> Integer | nil (49.0)

self から 1 バイト(0..255)を読み込み整数として返します。 既に EOF に達していれば nil を返します。

...そのため、最初のファイルを最後まで読んだ後は次のファイルの内
容を返します。

$
echo "foo" > file1
$
echo "bar" > file2
$
ruby argf.rb file1 file2

ARGF.getbyte # => 102
ARGF.getbyte # => 111
ARGF.getbyte # => 111
ARGF.getbyte # => 10
ARGF.getbyte...
...# => 98
ARGF.getbyte # => 97
ARGF.getbyte # => 114
ARGF.getbyte # => 10
ARGF.getbyte # => nil

@see ARGF.class#getc, ARGF.class#gets...
<< 1 2 > >>