ライブラリ
- ビルトイン (874)
クラス
-
ARGF
. class (24) - Dir (164)
- File (120)
-
File
:: Stat (12) - IO (478)
- Object (30)
-
Thread
:: Queue (10)
モジュール
- Enumerable (36)
キーワード
- <=> (12)
- advise (12)
- atime (12)
- autoclose= (12)
- autoclose? (12)
- binmode (12)
- children (7)
- chown (12)
- chunk (12)
- clone (12)
- close (22)
-
close
_ on _ exec= (12) -
close
_ on _ exec? (12) - ctime (12)
- dup (12)
- each (24)
-
each
_ byte (24) -
each
_ child (14) -
each
_ codepoint (24) - eof (12)
- eof? (12)
-
external
_ encoding (12) - fcntl (12)
- fdatasync (12)
- fileno (11)
- flock (12)
- flush (12)
- inspect (12)
-
internal
_ encoding (12) - lstat (12)
- mtime (12)
- path (24)
- pos (24)
- pos= (24)
- pread (8)
- pwrite (8)
- read (24)
- readbyte (12)
- readlines (36)
- reopen (36)
- rewind (12)
- seek (12)
-
set
_ encoding (36) -
set
_ encoding _ by _ bom (6) - size (12)
-
slice
_ before (24) - stat (12)
- sync (12)
- sysread (12)
- sysseek (12)
- syswrite (12)
- tell (24)
- then (14)
-
to
_ path (24) - truncate (12)
- write (12)
-
yield
_ self (16)
検索結果
先頭5件
-
File
# to _ path -> String (8019.0) -
オープン時に使用したパスを文字列で返します。
...作成されていたりする場合です。
//emlist[例][ruby]{
File.open("testfile") {|f| f.path } #=> "testfile"
File.open("/tmp/../tmp/xxx", "w") {|f| f.path } #=> "/tmp/../tmp/xxx"
File.open("/tmp", File::RDWR | File::TMPFILE){|f| f.path } #=> "/tmp"
//}......されている場合に発生します。
//emlist[例][ruby]{
File.open("testfile") {|f| f.path } #=> "testfile"
File.open("/tmp/../tmp/xxx", "w") {|f| f.path } #=> "/tmp/../tmp/xxx"
File.open("/tmp", File::RDWR | File::TMPFILE){|f| f.path } # IOError: File is un... -
IO
# readlines(limit) -> [String] (8019.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
..."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.readlines(",") } # =>... -
IO
# readlines(rs = $ / ) -> [String] (8019.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
..."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.readlines(",") } # =>... -
IO
# readlines(rs , limit) -> [String] (8019.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
..."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.readlines(",") } # =>... -
Thread
:: Queue # close -> self (8017.0) -
キューを close します。close 済みのキューを再度 open することはできません。
...キューを close します。close 済みのキューを再度 open することはできません。
close 後は以下のように動作します。
* Thread::Queue#closed? は true を返します
* Thread::Queue#close は無視されます
* Thread::Queue#enq/push/<< は ClosedQueueError... -
Enumerable
# chunk {|elt| . . . } -> Enumerator (8013.0) -
要素を前から順にブロックで評価し、その結果によって 要素をチャンクに分けた(グループ化した)要素を持つ Enumerator を返します。
...め upcase しています。
//emlist[例][ruby]{
# ファイルのエンコーディングは実際のファイルに合わせてください。
open("/usr/share/dict/words", "r:iso-8859-1") {|f|
f.chunk {|line| line[0].upcase }.each {|ch, lines| p [ch, lines.length] }
}
# => ["A", 17096]
#......の出力のハイフンの所で区切りたい場合を考えます。
//emlist[例][ruby]{
sep = "-"*72 + "\n" # ハイフンが72個の行
IO.popen("svn log README") {|f|
f.chunk {|line|
line != sep || nil
}.each {|_, lines|
pp lines
}
}
#=> ["r20018 | knu | 2008-10-29 13:20:42 +0......行が連続している場合のみ
チャンク化し、それ以外は素通しします。
//emlist[例][ruby]{
pat = /\A[A-Z][A-Za-z0-9_]+\#/
open(filename) {|f|
f.chunk {|line| pat =~ line ? $& : :_alone }.each {|key, lines|
if key != :_alone
print lines.sort.join('')
else... -
Enumerable
# slice _ before {|elt| bool } -> Enumerator (8013.0) -
パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。
...], [1, 2, 4], [5], [3], [1, 4, 2]]
# ChangeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}
# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}......# "svn proplist -R" の結果を分割する
# これは一要素が複数行にまたがっている
IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"]
# ["Properties... -
Enumerable
# slice _ before(pattern) -> Enumerator (8013.0) -
パターンがマッチした要素、もしくはブロックが真を返した要素から 次にマッチする手前までを チャンク化(グループ化)したものを繰り返す Enumerator を 返します。
...], [1, 2, 4], [5], [3], [1, 4, 2]]
# ChangeLog のエントリーを順に取る
open("ChangeLog") {|f|
f.slice_before(/\A\S/).each {|e| pp e}
}
# 上と同じだが、パターンでなくブロックを使う
open("ChangeLog") {|f|
f.slice_before {|line| /\A\S/ === line }.each {|e| pp e}
}......# "svn proplist -R" の結果を分割する
# これは一要素が複数行にまたがっている
IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f|
f.lines.slice_before(/\AProp/).each {|lines| p lines }
}
#=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"]
# ["Properties... -
File
:: Stat # <=>(o) -> Integer | nil (8013.0) -
ファイルの最終更新時刻を比較します。self が other よりも 新しければ正の数を、等しければ 0 を古ければ負の数を返します。 比較できない場合は nil を返します。
...Stat のインスタンスを指定します。
//emlist[][ruby]{
require 'tempfile' # for Tempfile
fp1 = Tempfile.open("first")
fp1.print "古い方\n"
sleep(1)
fp2 = Tempfile.open("second")
fp2.print "新しい方\n"
p File::Stat.new(fp1.path) <=> File::Stat.new(fp2.path) #=> -1
p File::Stat.ne... -
IO
# autoclose=(bool) (8013.0) -
auto-close フラグを設定します。
...close しません。
@param bool 真偽値でフラグを設定します
@see IO#autoclose?
f = open("/dev/null")
IO.for_fd(f.fileno)
# ...
f.gets # may cause Errno::EBADF
f = open("/dev/null")
IO.for_fd(f.fileno).autoclose = false
# ...
f.gets # won't cause Errno::EBADF... -
IO
# read(length = nil , outbuf = "") -> String | nil (8013.0) -
length バイト読み込んで、その文字列を返します。
...れば nil を返します。
ただし、length に nil か 0 が指定されている場合は、空文字列 "" を返します。
例えば、open(空ファイル) {|f| f.read } は "" となります。
@param length 読み込むサイズを整数で指定します。
nil が指......負の場合に発生します。
第二引数を指定した read の呼び出しでデータが空であった場合
(read が nil を返す場合)、outbuf は空文字列になります。
outbuf = "x" * 20;
io = File.open("/dev/null")
p io.read(10,outbuf)
p outbuf
=> nil
""...