168件ヒット
[1-100件を表示]
(0.102秒)
種類
- 変数 (96)
- モジュール関数 (60)
- インスタンスメソッド (12)
キーワード
-
$ -0 (12) -
$ / (12) -
$ DEFAULT _ INPUT (12) -
$ INPUT _ RECORD _ SEPARATOR (12) -
$ LAST _ PAREN _ MATCH (12) -
$ RS (12) -
$ _ (12) -
$ stdin (12) - file (12)
- loop (24)
- readline (12)
- readlines (12)
検索結果
先頭5件
-
Kernel
. # gets(rs = $ / ) -> String | nil (24238.0) -
ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。
...。
@return ファイルの終り(EOF)に到達した時、 nil を返します。
@raise Errno::EXXX 読み込みに失敗した場合に発生します。
//emlist[main.rb][ruby]{
ARGV << 'b.txt' << 'c.txt'
p gets #=> "hello\n"
p gets(nil) #=> "it\ncommon\n"
p gets("") #=> "ARGF\n\n"
p gets('、'......ct::ARGV を参照) をファイル名と\n# みなして、"
p gets #=> "それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。\n"
p gets #=> nil
p readline # end of file reached (EOFError)
//}
//emlist[b.txt][ruby]{
hello
it
common
//}
//emlist[c.t......xt][ruby]{
ARGF
# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}
@see $/,ARGF,Kernel.#readlines,Kernel.#readline... -
Kernel
$ $ stdin -> object (6143.0) -
標準入力です。
...$stdin に代入すれば十分です。
//emlist[例][ruby]{
# 標準入力の入力元 /tmp/foo に変更
$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}
ただし、Kernel.#gets など、特定の組み込みメソッドは
$stdin オ......って、Kernel.#gets などが正しく動作するには、
$stdin オブジェクトに代入したオブジェクトが以下のメソッドを
正しく実装していなければいけません。
gets, readline, readlines, getc, readchar, tell, seek,
pos=, rewind, fileno, to_io, eof,......byte,
binmode, closed?
//emlist[例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}
自プロセスだけでなく、子プロセスの標準入力もリダイレクトしたいときは
以下のように IO#reopen を使います。
//emlist[例][ruby]{
$std... -
Kernel
$ $ DEFAULT _ INPUT -> IO (6107.0) -
$< の別名
...$< の別名
require "English"
while line = $DEFAULT_INPUT.gets
p line
end
# end of sample.rb
ruby sample.rb < /etc/passwd
# => "hoge:x:500:501::/home/hoge:/bin/bash\n"
...... -
Kernel
$ $ INPUT _ RECORD _ SEPARATOR -> String | nil (6107.0) -
$/ の別名
...$/ の別名
require "English"
$INPUT_RECORD_SEPARATOR = '|'
array = []
while line = DATA.gets
array << line
end
p array #=> ["ugo|", "ego|", "fogo\n"]
__END__
ugo|ego|fogo... -
Kernel
$ $ LAST _ PAREN _ MATCH -> String | nil (6107.0) -
$+ の別名
...c=(http:.+?)>")
r2 = Regexp.compile("<a href=(http|ftp).+?>(.+?)</a>")
while line = DATA.gets
[ r1, r2 ].each {|rep|
rep =~ line
p $+
}
end
__END__
<tr> <td><img src=http://localhost/a.jpg></td> <td>ikkou</td> <td><a href=http://localhost/link.html>link</a></td> </tr>......#enf of sample.rb
$ ruby sample.rb
"http://localhost/a.jpg"
"link"... -
Kernel
$ $ RS -> String | nil (3107.0) -
$/ の別名
...$/ の別名
require "English"
$INPUT_RECORD_SEPARATOR = '|'
array = []
while line = DATA.gets
array << line
end
p array #=> ["ugo|", "ego|", "fogo\n"]
__END__
ugo|ego|fogo... -
Kernel
$ $ _ -> String | nil (129.0) -
最後に Kernel.#gets または Kernel.#readline で読み込んだ文字列です。 EOF に達した場合には、 nil になります。 (覚え方: Perlと同じ)
...最後に Kernel.#gets または Kernel.#readline で読み込んだ文字列です。
EOF に達した場合には、 nil になります。
(覚え方: Perlと同じ)
Kernel.#print のような Perl 由来の幾つかのメソッドは、引数を省略すると代わりに $_ を利用します......ーカルです。
Ruby起動時の初期値は nil です。
@see Kernel.#print, Kernel.#gets, Kernel.#readline, Object::ARGF
=== 例
example.txt:
foo
bar
baz
このとき、コマンド ruby -e 'print while gets' example.txt は次を出力します
foo
bar
baz
ただし、このプロ......グラムは次のように書く方がよりRuby的です。
//emlist[例][ruby]{
ARGF.each do |line|
print line
end
//}... -
Kernel
. # readlines(rs = $ / ) -> [String] (123.0) -
ARGFを Kernel.#gets(rs) でEOFまで読み込んで、その各行を要素としてもつ配列を返します。 行の区切りは引数 rs で指定した文字列になります。
...ARGFを Kernel.#gets(rs) でEOFまで読み込んで、その各行を要素としてもつ配列を返します。
行の区切りは引数 rs で指定した文字列になります。
rs に nil を指定すると行区切りなしとみなします。
空文字列 "" を指定すると連続......す。
//emlist[main.rb][ruby]{
ARGV << 'b.txt' << 'b.txt'
p readlines #=> ["hello\n", "it\n", "\n", "common\n", "hello\n", "it\n", "\n", "common\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines(nil) #=> ["hello\nit\n\ncommon\n", "hello\nit\n\ncommon\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines(""......) #=> ["hello\nit\n\n", "common\n", "hello\nit\n\n", "common\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines('it') #=> ["hello\nit", "\n\ncommon\n", "hello\nit", "\n\ncommon\n"]
p readlines #=> []
//}
//emlist[b.txt][ruby]{
hello
it
common
//}
@see $/,ARGF,Kernel.#gets, Kernel.#readline... -
Kernel
# file(*args) { . . . } -> Rake :: FileTask (107.0) -
ファイルタスクを定義します。
...ル名を指定します。
例:
file "config.cfg" => ["config.template"] do
open("config.cfg", "w") do |outfile|
open("config.template") do |infile|
while line = infile.gets
outfile.puts line
end
end
end
end
@see Rake::Task.define_task...