180件ヒット
[101-180件を表示]
(0.055秒)
別のキーワード
種類
- インスタンスメソッド (120)
- 特異メソッド (36)
- 文書 (12)
- 変数 (12)
クラス
-
ARGF
. class (72) - String (12)
- StringIO (60)
- StringScanner (12)
モジュール
- Kernel (12)
検索結果
先頭5件
-
ARGF
. class # gets(rs , limit , chomp: false) -> String | nil (30.0) -
ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。
...# $ ruby test.rb test.txt
# test.rb
ARGF.gets # => "line1\n"
例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt
# test.rb
ARGF.gets(2) # => "li"
例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby t......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... -
Kernel
$ $ stdin -> object (30.0) -
標準入力です。
...準入力です。
自プロセスの標準入力をリダイレクトしたいときは
$stdin に代入すれば十分です。
//emlist[例][ruby]{
# 標準入力の入力元 /tmp/foo に変更
$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻......正しく実装していなければいけません。
gets, readline, readlines, getc, readchar, tell, seek,
pos=, rewind, fileno, to_io, eof, each_line, each_byte,
binmode, closed?
//emlist[例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}
自プ......以下のように IO#reopen を使います。
//emlist[例][ruby]{
$stdin.reopen("/tmp/foo")
//}
また、リダイレクトしたあと
入力先をまた元に戻したい場合は以下のようにします。
//emlist[例][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する... -
ARGF
. class # getbyte -> Integer | nil (12.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 # readchar -> String (12.0) -
ARGFから 1 文字読み込んで、その文字に対応する String を返します。EOF に 到達した時には EOFErrorを発生します。
...rorを発生します。
@raise EOFError EOFに達した時発生する
$ echo "foo" > file
$ ruby argf.rb file
ARGF.readchar # => "f"
ARGF.readchar # => "o"
ARGF.readchar # => "o"
ARGF.readchar # => "\n"
ARGF.readchar # => end of file reached (EOFError)
@see ARGF.class#getc... -
StringIO
. new(string = & # 39;& # 39; , mode = & # 39;r+& # 39;) -> StringIO (12.0) -
StringIO オブジェクトを生成して返します。
...ーズされていて、mode が書き込み可能に設定されている場合に発生します。
//emlist[例][ruby]{
require 'stringio'
s = "foo"
io = StringIO.new(s)
p io.getc # => 102
p io.pos # => 1
p io.size # => 3
io << "bar"
p io.size # => 4
p s... -
StringIO
. open(string = & # 39;& # 39; , mode = & # 39;r+& # 39;) -> StringIO (12.0) -
StringIO オブジェクトを生成して返します。
...ーズされていて、mode が書き込み可能に設定されている場合に発生します。
//emlist[例][ruby]{
require 'stringio'
s = "foo"
io = StringIO.new(s)
p io.getc # => 102
p io.pos # => 1
p io.size # => 3
io << "bar"
p io.size # => 4
p s... -
StringIO
. open(string = & # 39;& # 39; , mode = & # 39;r+& # 39;) {|io| . . . } -> object (12.0) -
StringIO オブジェクトを生成して返します。
...ーズされていて、mode が書き込み可能に設定されている場合に発生します。
//emlist[例][ruby]{
require 'stringio'
s = "foo"
io = StringIO.new(s)
p io.getc # => 102
p io.pos # => 1
p io.size # => 3
io << "bar"
p io.size # => 4
p s...