942件ヒット
[1-100件を表示]
(0.024秒)
ライブラリ
モジュール
- Benchmark (36)
-
ERB
:: DefMethod (12) - Etc (24)
- JSON (36)
- Kernel (585)
- Math (12)
- ObjectSpace (60)
- Process (24)
-
Process
:: GID (24) -
Process
:: UID (24) - Readline (12)
- Signal (24)
- Syslog (48)
- Timeout (21)
キーワード
- String (12)
-
_ _ callee _ _ (12) -
_ _ method _ _ (12) - abort (24)
-
at
_ exit (12) - autoload (12)
- autoload? (12)
- benchmark (12)
- binding (12)
-
block
_ given? (12) - bm (12)
- bmbm (12)
- caller (36)
-
caller
_ locations (24) - catch (24)
-
def
_ erb _ method (12) -
define
_ finalizer (24) - dump (12)
- endgrent (12)
- endpwent (12)
- eval (24)
- exit (12)
- exit! (12)
- fail (36)
- fork (24)
- format (12)
- gamma (12)
- generate (12)
- gets (12)
- iterator? (12)
- lambda (18)
- loop (24)
-
memsize
_ of _ all (12) - open (24)
- open! (12)
- print (12)
- proc (19)
- raise (36)
- readline (24)
- reopen (12)
- require (12)
-
require
_ relative (12) -
set
_ trace _ func (12) - setpgrp (12)
- setpriority (12)
- sleep (24)
- sprintf (12)
- switch (48)
- test (24)
- throw (12)
- timeout (21)
-
trace
_ object _ allocations (12) - trap (24)
-
undefine
_ finalizer (12) - unparse (12)
- warn (8)
検索結果
先頭5件
-
Etc
. # endgrent -> nil (6101.0) -
Etc.#getgrent によって開始された /etc/group ファイルを読む プロセスを終了させファイルを閉じます。
Etc.#getgrent によって開始された /etc/group ファイルを読む
プロセスを終了させファイルを閉じます。
@see getgrent(3) -
Etc
. # endpwent -> nil (6101.0) -
Etc.#getpwent によって開始された /etc/passwdファイルを読む プロセスを終了させファイルを閉じます。
Etc.#getpwent によって開始された /etc/passwdファイルを読む
プロセスを終了させファイルを閉じます。
@see getpwent(3) -
Benchmark
. # bm(label _ width = 0 , *labels) {|rep| . . . } -> [Benchmark :: Tms] (73.0) -
Benchmark.#benchmark メソッドの引数を簡略化したものです。
...mlist[][ruby]{
require 'benchmark'
n = 50000
Benchmark.bm do |x|
x.report { for i in 1..n; a = "1"; end }
x.report { n.times do ; a = "1"; end }
x.report { 1.upto(n) do ; a = "1"; end }
end
#=>
#
# user system total real
# 1.033333 0.016667 1.016667 ( 0.492106)
# 1......'benchmark'
n = 50000
Benchmark.bm(7) do |x|
x.report("for:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
end
#=>
# user system total real
# for: 1.050000 0.000000......, ">avg:") do |x|
tf = x.report("for:") { for i in 1..n; a = "1"; end }
tt = x.report("times:") { n.times do ; a = "1"; end }
tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[tf + tt + tu, (tf + tt + tu) / 3]
end
#=>
# user system total real
# for:... -
Kernel
. # at _ exit { . . . } -> Proc (49.0) -
与えられたブロックをインタプリタ終了時に実行します。
...与えられたブロックをインタプリタ終了時に実行します。
at_exitがメソッドである点を除けば、END ブロックによる終了
処理の登録と同等です。登録した処理を取り消すことはできません。
spec/terminateも参照してください。......Proc オブジェクトで返します。
//emlist[例][ruby]{
3.times do |i|
at_exit{puts "at_exit#{i}"}
end
END{puts "END"}
at_exit{puts "at_exit"}
puts "main_end"
#=> main_end
# at_exit
# END
# at_exit2
# at_exit1
# at_exit0
//}
@see d:spec/control#END,Kernel.#exit!,Kernel.#fork... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (49.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d: pi = %f\n", min[0] + min[1], min[0]*4.0/(min[0]+min[1])
#......ムアウト
#!/usr/bin/env ruby
require 'timeout'
class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
=== 注意
timeout による割り込みは Thread によって実現されてい......= Time.now
begin
Timeout.timeout(t) {
p TCPSocket.gethostbyname("www.ruby-lang.org")
# (A)
}
ensure
p Time.now - start
end
# 実行例
=> ["helium.ruby-lang.org", [], 2, "210.251.121.214"]
0.689331
/usr/local/lib/ruby/1.6/timeout.rb:37: execution expired... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (49.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d: pi = %f\n", min[0] + min[1], min[0]*4.0/(min[0]+min[1])
#......ムアウト
#!/usr/bin/env ruby
require 'timeout'
class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
=== 注意
timeout による割り込みは Thread によって実現されてい......= Time.now
begin
Timeout.timeout(t) {
p TCPSocket.gethostbyname("www.ruby-lang.org")
# (A)
}
ensure
p Time.now - start
end
# 実行例
=> ["helium.ruby-lang.org", [], 2, "210.251.121.214"]
0.689331
/usr/local/lib/ruby/1.6/timeout.rb:37: execution expired... -
Kernel
. # abort -> () (43.0) -
Ruby プログラムをエラーメッセージ付きで終了します。終了ステータスは 1 固定です。
...stemExit => err
puts "end1 with #{err.inspect}"
end
begin
puts 'start2...'
raise RuntimeError.new
rescue
abort
ensure
puts 'end2...'
end
puts 'end' #実行されない
#(標準出力)
#=> start
# start1...
# end1 with #<SystemExit: error1>
# start2...
# end2...
#終了ステー... -
Kernel
. # abort(message) -> () (43.0) -
Ruby プログラムをエラーメッセージ付きで終了します。終了ステータスは 1 固定です。
...stemExit => err
puts "end1 with #{err.inspect}"
end
begin
puts 'start2...'
raise RuntimeError.new
rescue
abort
ensure
puts 'end2...'
end
puts 'end' #実行されない
#(標準出力)
#=> start
# start1...
# end1 with #<SystemExit: error1>
# start2...
# end2...
#終了ステー... -
Kernel
. # caller(range) -> [String] | nil (43.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...l.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []......+)(?::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
bar
p parse_caller(caller.first)
#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}
以下は......、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}...