クラス
-
ARGF
. class (24) - IO (324)
-
IRB
:: FileInputMethod (12) - Object (24)
- Tempfile (36)
-
Zlib
:: GzipReader (24)
キーワード
-
$ stdin (12) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - ARGF (24)
- DATA (12)
- IO (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 3
. 0 . 0 (5) - NKF (12)
- bigdecimal (12)
- delete (12)
- each (72)
-
each
_ line (72) - getbyte (12)
- getc (12)
- lineno (12)
- lineno= (12)
- open (12)
- pos (12)
- pos= (12)
- readchar (12)
- readline (60)
- readlines (36)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) - sysread (12)
- tell (12)
- timeout (21)
- unlink (12)
- 制御構造 (12)
検索結果
先頭5件
-
ARGF (48.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 を......表示
p [ARGF.filename, ARGV]
ARGF.skip
}
# => ["/tmp/foo", ["/tmp/bar"]]
# ["/tmp/bar", []]
# 最後まで読んだ後 (ARGV が空) の動作
p ARGF.gets # => nil
p ARGF.filename # => "-"
//}
Kernel.#gets など一部の組み込み関数は
ARGF.gets などこのオブ... -
Kernel
$ $ stdin -> object (48.0) -
標準入力です。
...$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}
ただし、Kernel.#gets など、特定の組み込みメソッドは
$stdin オブジェクトにメソッドを転送して実装されています。
従って、Kernel.#gets などが......していなければいけません。
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"
//}
自プロセスだけ......][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する
$stdin.reopen("/tmp/foo") # $stdin を /tmp/foo にリダイレクトする
gets # /tmp/foo から入力
$stdin.reopen stdin_old # 元に戻す
//}
$stdin はグローバルスコープです。... -
ruby 1
. 8 . 2 feature (42.0) -
ruby 1.8.2 feature ruby 1.8.2 での ruby 1.8.1 からの変更点です。
...コマンドライン引数に与えたファイルを読んだ後には標準入力を読まなくなりました。
((<ruby-dev:24452>))
: IO#gets [ruby] [bug]
"\377" を引数に受け取っても適切に振舞うようになりました。((<ruby-dev:24460>))
: Dir.glob [change]
ブロ......p_server [lib] [new]
: WEBrick::HTTPServlet::FileHandler#get_servlet [lib] [new]
=== 2004-09-03
: Struct.new [ruby] [bug]
同じ名前で二度定義したときのバグを修正しました。((<ruby-dev:24210>))
=== 2004-08-24
: CGI::Session::FileStore#initialize [lib] [bug]
セッショ......われるバグを修正しました。
=== 2004-08-23
: OpenSSL::SSL#pending [lib] [new]
=== 2004-08-14
: FileUtils.copy_entry [lib] [new]
: FileUtils::DryRun [lib] [new]
追加。
: FileUtils.mv [lib] [compat]
mv が :force オプションを受け付けるようになりました。
=== 20... -
IO
# readlines(limit , chomp: false) -> [String] (36.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...uby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlin......chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}
@see $/, IO#gets... -
IO
# readlines(rs = $ / , chomp: false) -> [String] (36.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...uby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlin......chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}
@see $/, IO#gets... -
IO
# readlines(rs , limit , chomp: false) -> [String] (36.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...uby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlin......chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}
@see $/, IO#gets... -
制御構造 (36.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...while 修飾した式の戻り値を
その値にすることもできます。
====[a:until] until
//emlist[例][ruby]{
until f.eof?
print f.gets
end
//}
文法:
until 式 [do]
...
end
式を評価した値が真になるまで、本体を繰り返して実......を伴った break により
until 式の戻り値をその値にすることもできます。
==== until修飾子
//emlist[例][ruby]{
print(f.gets) until f.eof?
//}
文法:
式 until 式
右辺の式を評価した値が真になるまで、左辺を繰り返して実行しま
す......ure 節を定義でき、これにより例外を処理することが
できます。
==== rescue修飾子
//emlist[例][ruby]{
open("nonexistent file") rescue STDERR.puts "Warning: #$!"
//}
文法:
式1 rescue 式2
式1で例外が発生したとき、式2を評価します。
以... -
ARGF
. class # getbyte -> Integer | nil (30.0) -
self から 1 バイト(0..255)を読み込み整数として返します。 既に EOF に達していれば nil を返します。
...め、最初のファイルを最後まで読んだ後は次のファイルの内
容を返します。
$ echo "foo" > file1
$ echo "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 # getc -> String | nil (30.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... -
NKF (30.0)
-
nkf(Network Kanji code conversion Filter, https://osdn.net/projects/nkf/) を Ruby から使うためのモジュールです。
...ンドの例です。
//emlist[例][ruby]{
#!/usr/local/bin/ruby
require 'nkf'
opt = ''
opt = ARGV.shift if ARGV[0][0] == ?-
while line = ARGF.gets
print NKF.nkf(opt, line)
end
//}
以下は、漢字コード判別コマンドの例です。
//emlist[例][ruby]{
#!/usr/local/bin/ruby
requir......=> "UTF8",
NKF::BINARY => "BINARY",
NKF::ASCII => "ASCII",
NKF::UNKNOWN => "UNKNOWN",
}
while file = ARGV.shift
str = open(file) {|io| io.gets(nil) }
printf "%-10s ", file
if str.nil?
puts "EMPTY"
else
puts CODES.fetch(NKF.guess(str))
end
end
//}
=== オプショ...