Ruby 2.0.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > ARGF.classクラス > readchar
readchar -> Integer[permalink][rdoc]ARGFから 1 文字読み込んで、その文字に対応する Fixnum を返します。EOF に到達した時には EOFErrorを発生します。
# カレントディレクトリから適当にファイルを選ぶ
ARGV.replace(
Dir.glob("*").select{|name| FileTest.file?(name)}
)
begin
c = ARGF.readchar
printf("%4c is %4d\n", c, c)
rescue EOFError
p $!
break
end while true
# 例
#...
#=> t is 116
#=> a is 97
#=> m is 109
#=> a is 97
#=>
#=> is 10
#<EOFError: end of file reached>
[SEE_ALSO] ARGF.class#getc