種類
- インスタンスメソッド (157)
- 特異メソッド (33)
検索結果
先頭5件
-
IO
. foreach(path , rs = $ / , chomp: false) -> Enumerator (8103.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}
//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO.write("t......", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.foreach("testfile", c......homp: true) { |x| print "GOT ", x }
# => GOT line1GOT line2,GOT line3
//}
@see $/... -
IO
. foreach(path , rs = $ / , chomp: false) {|line| . . . } -> nil (8103.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}
//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO.write("t......", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.foreach("testfile", c......homp: true) { |x| print "GOT ", x }
# => GOT line1GOT line2,GOT line3
//}
@see $/... -
IO
. readlines(path , rs = $ / , chomp: false , opts={}) -> [String] (8103.0) -
path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。
...emlist[例][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}
//emlist[例: rs を取り除く(chomp = true)][ruby]{
IO.write("testfile",......"line1,\rline2,\r\nline3,\n")
IO.readlines("testfile", chomp: true) # => ["line1,\rline2,", "line3,"]
IO.readlines("testfile", "\r", chomp: true) # => ["line1,", "line2,", "\nline3,\n"]
//}... -
IO
. readlines(path , rs = $ / , opts={}) -> [String] (8103.0) -
path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。
...、ファイルの読み込みに失敗した場合に発生します。
//emlist[例][ruby]{
IO.write("testfile", "line1\nline2,\nline3\n")
IO.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}... -
IO
# fileno -> Integer (8015.0) -
ファイル記述子を表す整数を返します。
...ファイル記述子を表す整数を返します。
@raise IOError 既に close されている場合に発生します。
//emlist[例][ruby]{
$stdin.fileno # => 0
$stdout.fileno # => 1
//}......ファイル記述子を表す整数を返します。
@raise IOError 既に close されている場合に発生します。
//emlist[例][ruby]{
$stdin.fileno # => 0
$stdout.fileno # => 1
//}
@see Dir#fileno... -
IO
# pid -> Integer | nil (8015.0) -
自身が IO.popen で作られたIOポートなら、子プロセスのプロセス ID を 返します。それ以外は nil を返します。
...自身が IO.popen で作られたIOポートなら、子プロセスのプロセス ID を
返します。それ以外は nil を返します。
@raise IOError 既に close されている場合に発生します。
//emlist[例][ruby]{
IO.popen("-") do |pipe|
if pipe
$stderr.puts "In pare......nt, child pid is #{pipe.pid}" # => In parent, child pid is 16013
else
$stderr.puts "In child, pid is #{$$}" # => In child, pid is 16013
end
end
//}... -
IO
# putc(ch) -> object (8015.0) -
文字 ch を self に出力します。 引数の扱いは Kernel.#putc と同じです。詳細はこちらを参照し てください。ch を返します。
...字コード(整数)で与えます。
@raise IOError 自身が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
$stdout.putc "A" # => A
$stdout.putc 65 # => A
//}
@see Kernel.#putc... -
IO
# to _ i -> Integer (8015.0) -
ファイル記述子を表す整数を返します。
...ファイル記述子を表す整数を返します。
@raise IOError 既に close されている場合に発生します。
//emlist[例][ruby]{
$stdin.fileno # => 0
$stdout.fileno # => 1
//}......ファイル記述子を表す整数を返します。
@raise IOError 既に close されている場合に発生します。
//emlist[例][ruby]{
$stdin.fileno # => 0
$stdout.fileno # => 1
//}
@see Dir#fileno... -
IO
# print(*arg) -> nil (8009.0) -
引数を IO ポートに順に出力します。引数を省略した場合は、$_ を出力します。
...引数を IO ポートに順に出力します。引数を省略した場合は、$_ を出力します。
@param arg Kernel.#print と同じです。
@raise IOError 自身が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合......に発生します。
//emlist[例][ruby]{
$stdout.print("This is ", 100, " percent.\n") # => This is 100 percent.
//}
@see Kernel.#print... -
IO
# puts(*obj) -> nil (8009.0) -
各 obj を self に出力し、それぞれの後に改行を出力します。 引数の扱いは Kernel.#puts と同じです。詳細はこちらを参照し てください。
...クトを指定します。Kernel.#puts と同じです。
@raise IOError 自身が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
$stdout.puts("this", "is", "a", "test", [1, [nil, 3]])
#=...