るりまサーチ

最速Rubyリファレンスマニュアル検索!
942件ヒット [1-100件を表示] (0.024秒)
トップページ > クエリ:end[x] > 種類:モジュール関数[x]

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. zlib end

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

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"]
//}...
<< 1 2 3 ... > >>