検索結果
先頭5件
-
ARGF
. class # getc -> String | nil (18157.0) -
self から 1 文字読み込んで返します。EOF に到達した時には nil を返します。
...foo" > file1
$ echo "bar" > file2
$ ruby argf.rb file1 file2
ARGF.getc # => "f"
ARGF.getc # => "o"
ARGF.getc # => "o"
ARGF.getc # => "\n"
ARGF.getc # => "b"
ARGF.getc # => "a"
ARGF.getc # => "r"
ARGF.getc # => "\n"
ARGF.getc # => nil
@see ARGF.class#getbyte, ARGF.class#gets... -
IO
# getc -> String | nil (18127.0) -
IO ポートから外部エンコーディングに従い 1 文字読み込んで返します。 EOF に到達した時には nil を返します。
...ープンされていなければ発生します。
例:
File.write("testfile", "test")
f = File.new("testfile")
p f.getc #=> "い"
p f.getc #=> "ろ"
p f.getc #=> "は"
f.read
f.getc #=> nil
@see IO#readchar... -
IO
# ungetc(char) -> nil (6114.0) -
指定された char を読み戻します。
...にオープンされていない時、
自身がまだ一度も read されていない時に発生します。
f = File.new("testfile") # => #<File:testfile>
c = f.getc # => "い"
f.ungetc(c) # => nil
f.getc # => "い"... -
String
# chr -> String (32.0) -
self の最初の文字だけを含む文字列を返します。
..."
a.chr #=> "a"
//}
Ruby 1.9 で IO#getc の戻り値が Integer から String を返すように変更になりました。
Ruby 1.8 以前と1.9以降の互換性を保つために String#chr が存在します。
例:
# ruby 1.8 系では STDIN.getc が 116 を返すため Integer#chr が......呼び出される
$ echo test | ruby -e "p STDIN.getc.chr" # => "t"
# ruby 1.9 系以降では STDIN.getc が "t" を返すため String#chr が呼び出される
$ echo test | ruby -e "p STDIN.getc.chr" # => "t"
@see String#ord, Integer#chr... -
IO (26.0)
-
基本的な入出力機能のためのクラスです。
...さい。
以下がテキスト読み込みメソッドです。
* IO.foreach
* IO.readlines
* IO#each_line
* IO#lines
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines
バイナリ読み込みメソッドは IO のエンコーディングの影響を......ディングの影響を受けません。
常に1バイトを単位として動作します。
例:
f = File.open('t.txt', 'r+:euc-jp')
p f.getc.encoding #=> Encoding::EUC_JP
p f.read(1).encoding #=> Encoding::ASCII_8BIT
====[a:io_encod......はそれぞれのメソッドの項を
参照して下さい。通常は前者の方法を使います。
例1:
f = File.open('file1')
p f.getc.encoding #=> Encoding::EUC_JP
例2:
f = File.open('t.txt', 'w+:shift_jis:euc-jp')
f.write "\xB4\xC1\xBB\xFA" # 文字列 "漢......照して下さい。
以下がテキスト読み込みメソッドです。
* IO.foreach
* IO.readlines
* IO#each_line
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines
バイナリ読み込みメソッドは IO のエンコーディングの影響を... -
IO
# sysread(maxlen , outbuf = "") -> String (18.0) -
read(2) を用いて入力を行ない、入力されたデータを 含む文字列を返します。stdio を経由しないので gets や getc や eof? などと混用すると思わぬ動作 をすることがあります。
...read(2) を用いて入力を行ない、入力されたデータを
含む文字列を返します。stdio を経由しないので gets や getc や eof? などと混用すると思わぬ動作
をすることがあります。
バイナリ読み込みメソッドとして動作します。
既... -
IO
# readchar -> String (14.0) -
IO ポートから 1 文字読み込んで返します。 EOF に到達した時には EOFError が発生します。
...で返します。
EOF に到達した時には EOFError が発生します。
テキスト読み込みメソッドとして動作します。
IO#getc との違いは EOF での振る舞いのみです。
@raise EOFError EOF に到達した時に発生します。
@raise IOError 自身が読み......込み用にオープンされていなければ発生します。
f = File.new("testfile")
p f.readchar #=> "い"
p f.readchar #=> "ろ"
p f.readchar #=> "は"
f.read
f.readchar #=> EOFError
@see IO#getc... -
ARGF
. class # getbyte -> Integer | nil (8.0) -
self から 1 バイト(0..255)を読み込み整数として返します。 既に EOF に達していれば nil を返します。
...cho "bar" > file2
$ ruby argf.rb file1 file2
ARGF.getbyte # => 102
ARGF.getbyte # => 111
ARGF.getbyte # => 111
ARGF.getbyte # => 10
ARGF.getbyte # => 98
ARGF.getbyte # => 97
ARGF.getbyte # => 114
ARGF.getbyte # => 10
ARGF.getbyte # => nil
@see ARGF.class#getc, ARGF.class#gets... -
ARGF
. class # gets(limit) -> String | nil (8.0) -
ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。
...est.txt
# test.rb
ARGF.gets("e") # => "line"
例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt
# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"
@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc... -
ARGF
. class # gets(limit , chomp: false) -> String | nil (8.0) -
ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。
...est.txt
# test.rb
ARGF.gets("e") # => "line"
例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt
# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"
@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc... -
ARGF
. class # gets(rs = $ / ) -> String | nil (8.0) -
ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。
...est.txt
# test.rb
ARGF.gets("e") # => "line"
例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt
# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"
@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...