ライブラリ
- ビルトイン (155)
クラス
-
ARGF
. class (110) - IO (22)
- Thread (23)
キーワード
- binmode (11)
- file (11)
- filename (11)
- path (11)
- readbyte (11)
- readchar (11)
- readline (22)
- readlines (22)
-
report
_ on _ exception (8) -
report
_ on _ exception= (8) -
safe
_ level (7) -
to
_ a (11)
検索結果
先頭5件
-
ARGF
. class # read(length = nil , str = nil) -> String | nil (26150.0) -
ARGVに指定されたファイルを先頭のファイルからlengthバイト読み込み、 その文字列をstrに出力します。読み込んだ文字列を返します。
...tr 出力先の文字列。内容は上書きされます。
$ echo "small" > small.txt
$ echo "large" > large.txt
$ ruby glark.rb small.txt large.txt
ARGF.read # => "small\nlarge"
ARGF.read(200) # => "small\nlarge"
ARGF.read(2) # => "sm"
ARGF.read(0) # => ""
@see IO#read... -
ARGF
. class # readline(rs = $ / ) -> String (14201.0) -
ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は EOFError を発生します。
...りなしとみなします。空文字列 "" を指定すると連続する改行を行
の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@raise EOFError EOFに達したら発生する
@see Kernel.#readline, ARGF.class#gets... -
ARGF
. class # readlines(rs = $ / ) -> Array (14201.0) -
ARGFの各行を配列に読み込んで返します。rsがnilの場合は要素に各ファイルを すべて読み込んだ配列を返します。
...。rsがnilの場合は要素に各ファイルを
すべて読み込んだ配列を返します。
@param rs 行区切り文字
@param limit 最大の読み込みバイト数
lines = ARGF.readlines
lines[0] # => "This is line one\n"
@see $/, Kernel.#readlines, IO#readlines... -
IO
# readline(rs = $ / ) -> String (14201.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 (14201.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] (14201.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...{ |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.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}
@see $/, IO#get... -
IO
# readlines(rs = $ / , chomp: false) -> [String] (14201.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...\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.readlines(",") } # => ["line1,", "\nline2,", "\nl......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... -
ARGF
. class # readbyte -> Integer (14113.0) -
自身から 1 バイトを読み込み整数として返します。 既に EOF に達していれば EOFError が発生します。
...が発生します。
@raise EOFError 既に EOF に達している場合に発生します。
$ echo "foo" > file
$ ruby argf.rb file
ARGF.readbyte # => 102
ARGF.readbyte # => 111
ARGF.readbyte # => 111
ARGF.readbyte # => 10
ARGF.readbyte # => end of file reached (EOFError)... -
ARGF
. class # readchar -> String (14113.0) -
ARGFから 1 文字読み込んで、その文字に対応する String を返します。EOF に 到達した時には EOFErrorを発生します。
...rorを発生します。
@raise EOFError EOFに達した時発生する
$ echo "foo" > file
$ ruby argf.rb file
ARGF.readchar # => "f"
ARGF.readchar # => "o"
ARGF.readchar # => "o"
ARGF.readchar # => "\n"
ARGF.readchar # => end of file reached (EOFError)
@see ARGF.class#getc... -
ARGF
. class # to _ a(rs = $ / ) -> Array (11101.0) -
ARGFの各行を配列に読み込んで返します。rsがnilの場合は要素に各ファイルを すべて読み込んだ配列を返します。
...。rsがnilの場合は要素に各ファイルを
すべて読み込んだ配列を返します。
@param rs 行区切り文字
@param limit 最大の読み込みバイト数
lines = ARGF.readlines
lines[0] # => "This is line one\n"
@see $/, Kernel.#readlines, IO#readlines... -
Thread
# report _ on _ exception -> bool (11017.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{......Thread.stop; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #......<Thread:0x00007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# report _ on _ exception=(newstate) (11017.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{......Thread.stop; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #......<Thread:0x00007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception...