別のキーワード
種類
- インスタンスメソッド (267)
- モジュール関数 (33)
- オブジェクト (11)
クラス
-
ARGF
. class (267)
モジュール
- Kernel (33)
キーワード
- codepoints (14)
-
each
_ char (22) -
each
_ codepoint (22) - gets (35)
-
inplace
_ mode (11) -
inplace
_ mode= (11) - inspect (11)
- path (11)
- pos (11)
- pos= (11)
- print (11)
- printf (11)
- putc (11)
- puts (11)
-
read
_ nonblock (9) - readline (11)
- readlines (11)
- readpartial (11)
-
set
_ encoding (22) - skip (11)
- tell (11)
-
to
_ s (11)
検索結果
先頭5件
-
ARGF (38116.0)
-
スクリプトに指定した引数 (Object::ARGV を参照) をファイル名とみなして、 それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。 ARGV が空なら標準入力を対象とします。 ARGV を変更すればこのオブジェクトの動作に影響します。
...ます。
//emlist[][ruby]{
while line = ARGF.gets
# do something
end
//}
は、
//emlist[][ruby]{
while argv = ARGV.shift
File.open(argv) {|file|
while line = file.gets
# do something
end
}
end
//}
のように動作します。
ARGF を処理するごとに ARGV の要素...... ARGF を読み込んだ後、再度 ARGF から内容を読むと
(ARGV が空なので)標準入力からの読み込みとなります。
//emlist[][ruby]{
ARGV.replace %w(/tmp/foo /tmp/bar)
ARGF.each {|line|
# 処理中の ARGV の内容を表示
p [ARGF.filename, ARGV]
ARGF.skip
}......# => ["/tmp/foo", ["/tmp/bar"]]
# ["/tmp/bar", []]
# 最後まで読んだ後 (ARGV が空) の動作
p ARGF.gets # => nil
p ARGF.filename # => "-"
//}
Kernel.#gets など一部の組み込み関数は
ARGF.gets などこのオブジェクトをレシーバとしたメソッドの... -
ARGF
. class # inplace _ mode -> String | nil (9154.0) -
c:ARGF#inplace で書き換えるファイルのバックアップに付加される拡 張子を返します。拡張子が設定されていない場合は空文字列を返します。イン プレースモードでない場合は nil を返します。
...c:ARGF#inplace で書き換えるファイルのバックアップに付加される拡
張子を返します。拡張子が設定されていない場合は空文字列を返します。イン
プレースモードでない場合は nil を返します。
Ruby 起動時の -i オプション や......ARGF.class#inplace_mode= で設定します。
例:
# $ echo "test" > test.txt
# $ ruby -i.bak test.rb test.txt
# $ cat test.txt # => "TEST"
# $ cat test.txt.bak # => "test"
# test.rb
ARGF.inplace_mode # => ".bak"
ARGF.each_line {|e|print e.upcase} # => "TEST"
例......:
# $ echo "test" > test.txt
# $ ruby test.rb test.txt
# $ cat test.txt # => "test"
# test.rb
ARGF.inplace_mode # => nil
ARGF.each_line {|e|print e.upcase} # => "TEST"
@see d:spec/rubycmd#cmd_option, ARGF.class#inplace_mode=... -
ARGF
. class # inplace _ mode=(ext) (9154.0) -
c:ARGF#inplace時にバックアップファイルに付加する拡張子を設定します。 ピリオドも含めて指定する必要があります。
...c:ARGF#inplace時にバックアップファイルに付加する拡張子を設定します。
ピリオドも含めて指定する必要があります。
バックアップを残さない場合は空文字列を指定します。
この機能は Windows では使用出来ません。
設定が......ことも出来ます。
@param ext インプレースモード時にバックアップファイルに付加する拡張子を
文字列で指定します。
ピリオドも含める必要があります。
$ ruby argf.rb file.txt
---- argf.rb ----
# 引数のファイ......き換える
ARGF.inplace_mode = '.bak'
ARGF.lines do |line|
print line.sub("foo","bar")
end
---- -i オプションを使う場合 ----
$ ruby -i.bak -p -e '$_.sub!("foo","bar")' file.txt
---- -i オプションを使う場合その2 ----
$ ruby -i.bak -n -e 'print $_.sub("fo... -
ARGF
. class # pos -> Integer (9142.0) -
ARGFが現在開いているファイルのファイルポインタの現在の位置をバイト単位 の整数で返します。
...
ARGFが現在開いているファイルのファイルポインタの現在の位置をバイト単位
の整数で返します。
ARGF.pos # => 0
ARGF.gets # => "This is line one\n"
ARGF.pos # => 17
@see IO#pos, IO#tell, ARGF.class#pos=... -
ARGF
. class # pos=(n) (9136.0) -
ARGFが開いているファイルのファイルポインタを指定位置に移動します。
...
ARGFが開いているファイルのファイルポインタを指定位置に移動します。
@param n 先頭からのオフセットをバイト単位の整数で指定します。
ARGF.pos = 17
ARGF.gets # => "This is line two\n"
@see IO#pos=, ARGF.class#pos... -
ARGF
. class # skip -> self (9126.0) -
現在開いている処理対象のファイルをクローズします。 次回の読み込みは次の引数が処理対象になります。 self を返します。
...いている処理対象のファイルをクローズします。
次回の読み込みは次の引数が処理対象になります。
self を返します。
$ echo "foo" > foo
$ echo "bar" > bar
$ ruby argf.rb foo bar
ARGF.filename # => "foo"
ARGF.skip
ARGF.filename # => "bar"... -
ARGF
. class # readpartial(maxlen , outbuf = nil) -> String (9124.0) -
IO#readpartialを参照。ARGF.class#read などとは違って複数ファ イルを同時に読み込むことはありません。
...IO#readpartialを参照。ARGF.class#read などとは違って複数ファ
イルを同時に読み込むことはありません。
@param maxlen 読み込む長さの上限を整数で指定します。
@param outbuf 読み込んだデータを格納する String オブジェクトを指定し......ます。
@see IO#readpartial, ARGF.class#read_nonblock... -
ARGF
. class # each _ codepoint -> Enumerator (9120.0) -
self の各コードポイントに対して繰り返しブロックを呼びだします。
...す。
例:
# $ echo "line1\n" > test1.txt
# $ echo "line2\n" > test2.txt
# $ ruby test.rb test1.txt test2.txt
# test.rb
ARGF.each_codepoint # => #<Enumerator: ARGF:each_codepoint>
ARGF.each_codepoint{|e|print e, ","} # => 108,105,110,101,49,10,108,105,110,101,50,10,... -
ARGF
. class # each _ codepoint { |c| . . . } -> self (9120.0) -
self の各コードポイントに対して繰り返しブロックを呼びだします。
...す。
例:
# $ echo "line1\n" > test1.txt
# $ echo "line2\n" > test2.txt
# $ ruby test.rb test1.txt test2.txt
# test.rb
ARGF.each_codepoint # => #<Enumerator: ARGF:each_codepoint>
ARGF.each_codepoint{|e|print e, ","} # => 108,105,110,101,49,10,108,105,110,101,50,10,... -
ARGF
. class # codepoints -> Enumerator (9118.0) -
このメソッドは obsolete です。 代わりに ARGF.class#each_codepoint を使用してください。 使用すると警告メッセージが表示されます。
...このメソッドは obsolete です。
代わりに ARGF.class#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。...