ライブラリ
モジュール
- FileTest (318)
- FileUtils (559)
- Find (24)
- JSON (36)
- Kernel (324)
- Marshal (24)
- ObjectSpace (12)
-
OpenSSL
:: ASN1 (12) -
OpenSSL
:: Random (48) -
Profiler
_ _ (18) - Shellwords (24)
- Syslog (48)
- Timeout (21)
-
WEBrick
:: HTTPUtils (24)
キーワード
-
_ _ dir _ _ (12) -
allocation
_ sourcefile (12) - blockdev? (12)
- caller (36)
- cd (24)
- chardev? (12)
- chdir (24)
- chmod (12)
-
chmod
_ R (12) - chown (12)
-
chown
_ R (12) - cmp (12)
-
compare
_ file (12) -
compare
_ stream (12) - copy (12)
-
copy
_ entry (12) -
copy
_ file (12) -
copy
_ stream (12) - cp (12)
-
cp
_ lr (7) -
cp
_ r (12) - decode (12)
- directory? (12)
- dump (36)
- egd (12)
-
egd
_ bytes (12) - empty? (9)
- executable? (12)
-
executable
_ real? (12) - exist? (12)
- exists? (9)
- fail (36)
- file? (12)
- find (24)
- gets (12)
- getwd (12)
- grpowned? (12)
- identical? (24)
- install (12)
- link (12)
- ln (12)
-
ln
_ s (12) -
ln
_ sf (12) - load (12)
-
load
_ file (12) -
load
_ file! (12) -
load
_ mime _ types (12) -
load
_ random _ file (12) - makedirs (12)
- mask (12)
- mask= (12)
-
mime
_ type (12) - mkdir (12)
-
mkdir
_ p (12) - mkpath (12)
- move (12)
- mv (12)
- open (32)
- open! (12)
- owned? (12)
- pipe? (12)
-
print
_ profile (6) - pwd (12)
- raise (36)
- readable? (12)
-
readable
_ real? (12) - readline (12)
- remove (12)
-
remove
_ dir (12) -
remove
_ entry (12) -
remove
_ entry _ secure (12) -
remove
_ file (12) - reopen (12)
- require (12)
-
require
_ relative (12) - rm (12)
-
rm
_ f (12) -
rm
_ r (12) -
rm
_ rf (12) - rmdir (12)
- rmtree (12)
-
safe
_ unlink (12) -
set
_ trace _ func (12) - setgid? (12)
- setuid? (12)
- shellescape (12)
- shelljoin (12)
- size (12)
- size? (12)
- socket? (12)
- spawn (48)
-
start
_ profile (6) - sticky? (12)
-
stop
_ profile (6) - symlink (12)
- symlink? (12)
- system (28)
- test (24)
- timeout (21)
- touch (12)
- uptodate? (12)
-
world
_ readable? (12) -
world
_ writable? (12) - writable? (12)
-
writable
_ real? (12) -
write
_ random _ file (12) - zero? (12)
検索結果
先頭5件
-
Kernel
. # caller(start , length) -> [String] | nil (13.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
b... -
Kernel
. # set _ trace _ func(proc) -> Proc (13.0) -
Ruby インタプリタのイベントをトレースする Proc オブジェクトとして 指定された proc を登録します。 nil を指定するとトレースがオフになります。
...ます。
標準添付の debug、tracer、
profile はこの組み込み関数を利用して実現されています。
=== ブロックパラメータの意味
渡す Proc オブジェクトのパラメータは
//emlist[][ruby]{
proc{|event, file, line, id, binding, klass| "..." }
//}
で、......への突入。
"end": クラス定義、特異クラス定義、モジュール定義の終了。
"raise": 例外の発生。
//}
: file
実行中のプログラムのソースファイル名 (文字列)。
: line
実行中のプログラムのソースファイル上の行番号 (... -
Marshal
. # dump(obj , limit = -1) -> String (13.0) -
obj を指定された出力先に再帰的に出力します。
...)
* システムがオブジェクトの状態を保持するもの。具体的には以下のイン
スタンス。Dir, File::Stat, IO とそのサブクラス
File, Socket など。
* MatchData, Data, Method, UnboundMethod,
Proc, Thread, ThreadGroup, Continuation
のインスタン... -
Marshal
. # dump(obj , port , limit = -1) -> IO (13.0) -
obj を指定された出力先に再帰的に出力します。
...)
* システムがオブジェクトの状態を保持するもの。具体的には以下のイン
スタンス。Dir, File::Stat, IO とそのサブクラス
File, Socket など。
* MatchData, Data, Method, UnboundMethod,
Proc, Thread, ThreadGroup, Continuation
のインスタン... -
Shellwords
. # shellescape(str) -> String (13.0) -
文字列を Bourne シェルのコマンドライン中で安全に使えるようにエスケープします。
...ープします。
@param str エスケープの対象となる文字列を指定します。
@return エスケープされた文字列を返します。
例:
require 'shellwords'
pattern = 'Jan 15'
puts "grep #{Shellwords.shellescape(pattern)} file"
# => grep Jan\ 15 file... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (13.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...るなどの工夫が必要です。
例 外部コマンドのタイムアウト
require 'timeout'
# テスト用のシェルをつくる。
File.open("loop.sh", "w"){|fp|
fp.print <<SHELL_EOT
#!/bin/bash
S="scale=10"
M=32767
trap 'echo "$S; $m1/($m1+$m2)*4" | bc ; echo "count......cho "$S;$x^2+$y^2 < 1.0" | bc)
echo $x $y $c
if [ $c -eq 1 ]
then
let m1++
else
let m2++
fi
done
SHELL_EOT
}
File.chmod(0755, "loop.sh")
t = 10 # 10 秒でタイムアウト
begin
pid = nil
com = nil
Timeout.timeout(t) {
# system だと... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (13.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...るなどの工夫が必要です。
例 外部コマンドのタイムアウト
require 'timeout'
# テスト用のシェルをつくる。
File.open("loop.sh", "w"){|fp|
fp.print <<SHELL_EOT
#!/bin/bash
S="scale=10"
M=32767
trap 'echo "$S; $m1/($m1+$m2)*4" | bc ; echo "count......cho "$S;$x^2+$y^2 < 1.0" | bc)
echo $x $y $c
if [ $c -eq 1 ]
then
let m1++
else
let m2++
fi
done
SHELL_EOT
}
File.chmod(0755, "loop.sh")
t = 10 # 10 秒でタイムアウト
begin
pid = nil
com = nil
Timeout.timeout(t) {
# system だと... -
Kernel
. # spawn(command , options={}) -> Integer (9.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
引数を外部コマンドとして実行しますが、生成した
子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
=== 引数の解釈
この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。
@param command コマンドを文字列で指定します。
@param env 更新する環境変数を表す Hash
@param options オプションパラメータ Hash... -
Kernel
. # spawn(env , command , options={}) -> Integer (9.0) -
引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
引数を外部コマンドとして実行しますが、生成した
子プロセスの終了を待ち合わせません。生成した子プロセスのプロセスIDを返します。
=== 引数の解釈
この形式では command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます。
@param command コマンドを文字列で指定します。
@param env 更新する環境変数を表す Hash
@param options オプションパラメータ Hash... -
Kernel
. # fail -> () (7.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...ている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': No such file or directory - "nonexist" (Errno::ENOENT)
end
//}
引数を渡した場合は、例外メッセージ message を持った error_type の示す例...