ライブラリ
- ビルトイン (473)
-
io
/ console (11) -
io
/ console / size (22)
キーワード
- binread (11)
- binwrite (11)
- console (11)
-
console
_ size (11) -
copy
_ stream (22) -
default
_ console _ size (11) -
for
_ fd (11) - foreach (22)
- new (11)
- open (22)
- pipe (88)
- popen (154)
- read (33)
- readlines (33)
- select (11)
- sysopen (11)
-
try
_ convert (11) - write (22)
検索結果
先頭5件
-
IO
. binread(path , length = nil , offset = 0) -> String | nil (2.0) -
path で指定したファイルを open し、offset の所まで seek し、 length バイト読み込みます。
...ist[例][ruby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...\n")
IO.binread("testfile") # => "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
IO.binread("testfile", 20) # => "This is line one\nThi"
IO.binread("test......file", 20, 10) # => "ne one\nThis is line "
//}
@see IO.read... -
IO
. binwrite(path , string , offset=nil) -> Integer (2.0) -
path で指定されるファイルを開き、string を書き込み、 閉じます。
...書き込み、
閉じます。
ファイルを開くときの mode が "rb:ASCII-8BIT" で、バイナリモードが有効
である点以外は IO.write と同じです。
Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドを実行し、コマンドの出力を......89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52
# binwriteを使用した場合: どの環境でも正しく保存できる。
IO.binwrite('white.binmode.png', png)
puts IO.binread('white.binmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 4......。
IO.write('white.txtmode.png', png)
puts IO.binread('white.txtmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 (Linux/Macの場合
# => 89 50 4e 47 0d 0d 0a 1a 0d 0a 00 00 00 0d 49 48 (Windowsの場合
//}
@see c:IO#io_binmode, IO.w... -
IO
. console -> File | nil (2.0) -
端末を File オブジェクトで返します。
...端末を File オブジェクトで返します。
require "io/console"
IO.console # => #<File:/dev/tty>
プロセスが端末から切り離された状態で実行すると nil を返します。
戻り値はプラットフォームや環境に依存します。... -
IO
. console _ size -> [Integer , Integer] (2.0) -
端末のサイズを [rows, columns] で返します。
...端末のサイズを [rows, columns] で返します。
io/console が利用できない場合は、IO.default_console_size
の値を返します。
@see IO.default_console_size... -
IO
. copy _ stream(src , dst , copy _ length = nil) -> Integer (2.0) -
指定された src から dst へコピーします。 コピーしたバイト数を返します。
...指定された src から dst へコピーします。
コピーしたバイト数を返します。
コピー元の src が IO オブジェクトの場合は、src のオフセットから
ファイル名の場合はファイルの最初からコピーを開始します。
コピー先の dst......す。
src が IO オブジェクトでかつ src_offset が指定されている場合、
src のオフセット(src.pos)は変更されません。
@param src コピー元となる IO オブジェクトかファイル名を指定します。
@param dst コピー先となる IO オブジェク......数値で指定します。
//emlist[例][ruby]{
IO.write("filetest", "abcdefghij")
IO.copy_stream("filetest", "filecopy", 2) # => 2
IO.read("filecopy") # => "ab"
IO.copy_stream("filetest", "filecopy", 3, 4) # => 3
IO.read("filecopy") # => "e... -
IO
. copy _ stream(src , dst , copy _ length , src _ offset) -> Integer (2.0) -
指定された src から dst へコピーします。 コピーしたバイト数を返します。
...指定された src から dst へコピーします。
コピーしたバイト数を返します。
コピー元の src が IO オブジェクトの場合は、src のオフセットから
ファイル名の場合はファイルの最初からコピーを開始します。
コピー先の dst......す。
src が IO オブジェクトでかつ src_offset が指定されている場合、
src のオフセット(src.pos)は変更されません。
@param src コピー元となる IO オブジェクトかファイル名を指定します。
@param dst コピー先となる IO オブジェク......数値で指定します。
//emlist[例][ruby]{
IO.write("filetest", "abcdefghij")
IO.copy_stream("filetest", "filecopy", 2) # => 2
IO.read("filecopy") # => "ab"
IO.copy_stream("filetest", "filecopy", 3, 4) # => 3
IO.read("filecopy") # => "e... -
IO
. default _ console _ size -> [Integer , Integer] (2.0) -
デフォルトの端末のサイズを [rows, columns] で返します。
デフォルトの端末のサイズを [rows, columns] で返します。 -
IO
. for _ fd(fd , mode = "r" , **opts) -> IO (2.0) -
オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。
...オープン済みのファイルディスクリプタ fd に対する新しい
IO オブジェクトを生成して返します。
IO.open にブロックが与えられた場合、IO オブジェクトを生成しそれを引数としてブロックを
実行します。ブロックの終了と......ともに fd はクローズされます。ブロックの結果を返します。
IO.new, IO.for_fd はブロックを受け付けません。
=== キーワード引数
このメソッドは以下のキーワード引数を利用できます。
* :mode mode引数と同じ意味です
* :extern......用いられます。
@param fd ファイルディスクリプタである整数を指定します。
@param mode Kernel.#open と同じ形式で IO のモードを指定します。File::Constants::RDONLY などの
定数(数値)でモードを指定できます。詳細は組み込......。
* :autoclose 偽を渡すと close時/GCでのファイナライザ呼出時に fd を close しません。
* :path 文字列を渡すと、IO#path メソッドがその値を返すようになります。
また、String#encode で説明されている :invalid => :replace などの
変換... -
IO
. foreach(path , rs = $ / ) -> Enumerator (2.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......estfile", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
@see $/... -
IO
. foreach(path , rs = $ / ) {|line| . . . } -> nil (2.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......estfile", "line1,line2,line3")
IO.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}
@see $/... -
IO
. foreach(path , rs = $ / , chomp: false) -> Enumerator (2.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...