66件ヒット
[1-66件を表示]
(0.030秒)
クラス
- IO (22)
検索結果
先頭5件
-
IO
. foreach(path , rs = $ / , chomp: false) -> Enumerator (18156.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...テキスト読み込みメソッドとして動作します。
path が空ファイルの場合、何もせずに nil を返します。
Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドの出力を読み取ります。
@param path ファイル名を表す文字......by]{
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("testf......ne1,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", chomp:... -
IO
. foreach(path , rs = $ / , chomp: false) {|line| . . . } -> nil (18156.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...テキスト読み込みメソッドとして動作します。
path が空ファイルの場合、何もせずに nil を返します。
Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドの出力を読み取ります。
@param path ファイル名を表す文字......by]{
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("testf......ne1,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", chomp:... -
IO
. foreach(path , rs = $ / ) -> Enumerator (18144.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...テキスト読み込みメソッドとして動作します。
path が空ファイルの場合、何もせずに nil を返します。
Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドの出力を読み取ります。
@param path ファイル名を表す文字......by]{
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("testf......ile", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
@see $/... -
IO
. foreach(path , rs = $ / ) {|line| . . . } -> nil (18144.0) -
path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。
...テキスト読み込みメソッドとして動作します。
path が空ファイルの場合、何もせずに nil を返します。
Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドの出力を読み取ります。
@param path ファイル名を表す文字......by]{
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("testf......ile", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
@see $/... -
Open3 (6024.0)
-
プログラムを実行し、そのプロセスの標準入力・標準出力・ 標準エラー出力にパイプをつなぎます。
...果を受け取る。
require "open3"
stdin, stdout, stderr = *Open3.popen3('nroff -man')
# こちらから書く
Thread.fork {
File.foreach('/usr/man/man1/ruby.1') do |line|
stdin.print line
end
stdin.close # または close_write
}
# こちらから読む
stdou... -
net
/ pop (72.0) -
このライブラリは、POP3 (Post Office Protocol version 3) を 用いてPOPサーバからメールを受信する機能を提供するライブラリです。
...tderr.puts 'no mail.'
else
pop.mails.each_with_index do |m, idx| # 各メッセージにアクセスする
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}
m.delete
end
$stderr.puts "#{pop.mails.size} mails popped."
end
pop.finish......op|
if pop.mails.empty?
$stderr.puts 'no mail.'
else
pop.mails.each_with_index do |m, idx|
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}
m.delete
end
$stderr.puts "#{pop.mails.size} mails popped."
end
}
Net::POP3#dele......YourPassword') {|pop|
# 残りのコードは同じ
}
この方法はクラス自体を変えるので、クラスメソッドの start や foreach、
delete_all、auth_only なども APOP とともに使えます。
==== UIDL コマンドを使って特定のメールだけを取り出す... -
IO (66.0)
-
基本的な入出力機能のためのクラスです。
...の影響をうけます。
詳しくは「io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。
* IO.foreach
* IO.readlines
* IO#each_line
* IO#lines
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines
バイ......IO#read_nonblock
* IO#readpartial
* IO#sysread
また書き込みメソッド IO#write も IO のエンコーディングの影響を受けます。
IO のすべての書き込みメソッドは内部で IO#write を呼びますので、
書き込みメソッドはすべて IO のエンコーデ......連のメソッドはエンコーディングの影響を受けません。
常に1バイトを単位として動作します。
例:
f = File.open('t.txt', 'r+:euc-jp')
p f.getc.encoding #=> Encoding::EUC_JP
p f.read(1).encoding #=> Encod......の影響をうけます。
詳しくは「io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。
* IO.foreach
* IO.readlines
* IO#each_line
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines
バイナリ読み... -
CSV (36.0)
-
このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。
...=== 読み込み
//emlist[][ruby]{
require "csv"
csv_text = <<~CSV_TEXT
Ruby,1995
Rust,2010
CSV_TEXT
IO.write "sample.csv", csv_text
# ファイルから一行ずつ
CSV.foreach("sample.csv") do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]
# ファイルから一度に
p......parse(csv_text)
# => [["Ruby", "1995"], ["Rust", "2010"]]
//}
=== 書き込み
//emlist[][ruby]{
require 'csv'
# ファイルへ書き込み
CSV.open("path/to/file.csv", "wb") do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
# 文字列へ書き込み
csv_st......IO and String objects
passed into CSV have the proper Encoding set and everything should just work.
CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
One minor exception comes when generating CSV into...