るりまサーチ

最速Rubyリファレンスマニュアル検索!
946件ヒット [1-100件を表示] (0.097秒)

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Kernel$$CHILD_STATUS -> Process::Status | nil (12308.0)

$? の別名

...
$
? の別名

require "English"

out = `wget https://www.ruby-lang.org/en/about/license.txt -O - 2>/dev/null`

if $CHILD_STATUS.to_i == 0
print "wget success\n"
out.split(/\n/).each { |line|
printf "%s\n", line
}
else
print "wget failed\n"
end...

Kernel$$stdin -> object (12286.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, each_...
...byte,
binmode, closed?

//emlist[例][ruby]{
$
stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}

自プロセスだけでなく、子プロセスの標準入力もリダイレクトしたいときは
以下のように IO#reopen を使います。

//emlist[例][ruby]{
$
std...

Kernel$$stderr -> object (12274.0)

標準エラー出力です。

...ject::STDERR です。

$
stderr に代入するオブジェクトには
write という名前のメソッドが定義されていなければいけません。

自プロセスの標準エラー出力をリダイレクトしたいときには、
$
stderr に代入すれば十分です。

//emlist[...
.../tmp/foo に変更
$
stderr = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$
stderr = STDERR # 元に戻す
//}

自プロセスだけでなく、子プロセスの標準エラー出力も
リダイレクトしたいときは以下のように IO#reopen を使います。

//emlist[...
...ruby]{
$
stderr.reopen("/tmp/foo", "w")
//}

また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。

//emlist[例][ruby]{
stderr_old = $stderr.dup # 元の $stderr を保存する
$
stderr.reopen("/tmp/foo") # $stderr を /tmp/fo...

Kernel$$DEFAULT_OUTPUT -> IO (12226.0)

$> の別名

...
$
> の別名

require "English"

dout = $DEFAULT_OUTPUT.dup
$
DEFAULT_OUTPUT.reopen("out.txt", "w")
print "foo"
$
DEFAULT_OUTPUT.close
$
DEFAULT_OUTPUT = dout
p "bar" # => bar
p File.read("out.txt") #=> foo...

Kernel$$LAST_MATCH_INFO -> MatchData | nil (12220.0)

$~ の別名

...
$
~ の別名

require "English"

str = "<a href=https://www.ruby-lang.org/en/about/license.txt>license</a>"

if /<a href=(.+?)>/ =~ str
p $LAST_MATCH_INFO[0] #=> "<a href=https://www.ruby-lang.org/en/about/license.txt>"
p $LAST_MATCH_INFO[1] #=> "https://www.ruby-lang.org/en/about/lic...
...ense.txt"
p $LAST_MATCH_INFO[2] #=> nil
end...

絞り込み条件を変える

Kernel$$FIELD_SEPARATOR -> String | nil (12209.0)

$; の別名

...
$
; の別名

require "English"

str = "hoge,fuga,ugo,bar,foo"
p str.split #=> ["hoge,fuga,ugo,bar,foo"]
$
FIELD_SEPARATOR = ","
p str.split #=> ["hoge", "fuga", "ugo", "bar", "foo"]...

Kernel$$INPUT_LINE_NUMBER -> Integer (12209.0)

$. の別名

...
$
. の別名

1 e
2 f
3 g
4 h
5 i
# end of a.txt

require "English"

File.foreach(ARGV.at(0)){|line|
# read line
}
p $INPUT_LINE_NUMBER
# end of sample.rb

ruby sample.rb a.txt
#=> 5...

Kernel$$INPUT_RECORD_SEPARATOR -> String | nil (12209.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$$DEFAULT_INPUT -> IO (12208.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"
......
<< 1 2 3 ... > >>