るりまサーチ

最速Rubyリファレンスマニュアル検索!
2343件ヒット [1-100件を表示] (0.106秒)
トップページ > クエリ:t[x] > クエリ:begin[x]

別のキーワード

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

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

tsort (26120.0)

tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。

...tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。

=== Example

//emlist[][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end

{1=>[2, 3],...
...=>[]}.tsort
#=> [3, 2, 1, 4]

{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
#=> [[4], [2, 3], [1]]
//}

=== より現実的な例

非常に単純な `make' に似たツールは以下のように実装できます。

//emlist[][ruby]{
require 'tsort'

class Make
def initialize...
...gth != 1
fs = ns.delete_if {|n| Array === n}
raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
end
n = ns.first
if Array === n
outputs, inputs, block = n
inputs_time = inputs.map {|f| File.mtime f}.max
begin

outputs_ti...

MatchData#begin(n) -> Integer | nil (21237.0)

n 番目の部分文字列先頭のオフセットを返します。

...範囲外の n を指定した場合に発生します。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.begin(0) # => 0
p $~.begin(1) # => 0
p $~.begin(2) # => 3
p $~.begin(3) # => nil
p $~.begin(4) # => `begin': index 4 out of matches (IndexError)
//}

@see MatchData#end...

Enumerator::ArithmeticSequence#begin -> Numeric (21101.0)

初項 (始端) を返します。

...初項 (始端) を返します。

@see Enumerator::ArithmeticSequence#end...

Enumerator::ArithmeticSequence#begin -> Numeric | nil (21101.0)

初項 (始端) を返します。

...初項 (始端) を返します。

@see Enumerator::ArithmeticSequence#end...

Range#begin -> object (18235.0)

始端の要素を返します。 始端を持たない範囲オブジェクトの場合、begin はnilを返しますが, first は例外 RangeError が発生します。

...場合、begin はnilを返しますが, first は例外 RangeError が発生します。

//emlist[例][ruby]{
# 始端を持つ場合
p (1..5).begin # => 1
p (1..0).begin # => 1
p (1..5).first # => 1
p (1..0).first # => 1

# 始端を持たない場合
p (..5).begin #=> nil
p (..5).first #=> Range...

絞り込み条件を変える

Timeout.#timeout(sec, exception_class = nil) {|i| ... } -> object (9272.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...c 秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
T
imeout::Error が発生します。

exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはい...
...@param exception_class タイムアウトした時、発生させる例外を指定します.

例 長い計算のタイムアウト
require 'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t
= 5
min =...
...e Timeout::Error
puts "timeout"
end

printf "%d: pi = %f\n", min[0] + min[1], min[0]*4.0/(min[0]+min[1])
#例
#=> 417519: pi = 3.141443

例 独自の例外を発生させるタイムアウト
#!/usr/bin/env ruby

require 'timeout'

class MYError < Exception;end
begin

T
imeout...
....
@param exception_class タイムアウトした時、発生させる例外を指定します.
@param message エラーメッセージを指定します.省略した場合は
"execution expired" になります.

例 長い計算のタイムアウト
require 'timeout'

def calc_p...
...y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t
= 5
min = [ 0, 0]
begin

T
imeout.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])
#例
#=> 417...

Timeout.#timeout(sec, exception_class, message) {|i| ... } -> object (9272.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...c 秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
T
imeout::Error が発生します。

exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはい...
....
@param exception_class タイムアウトした時、発生させる例外を指定します.
@param message エラーメッセージを指定します.省略した場合は
"execution expired" になります.

例 長い計算のタイムアウト
require 'timeout'

def calc_p...
...y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t
= 5
min = [ 0, 0]
begin

T
imeout.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])
#例
#=> 417...

Exception#backtrace_locations -> [Thread::Backtrace::Location] (9206.0)

バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。

...ption#backtraceに似ていますが、
T
hread::Backtrace::Location の配列を返す点が異なります。

現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。

//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Dat...
...month, -1).day == 31
raise "#{month} is not long month"
end

def get_exception
return begin
yield
rescue => e
e
end
end

e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_ex...
...ception'", "test.rb:15:in `<main>'"]
//}

@see Exception#backtrace...

Exception#exception(error_message) -> Exception (9206.0)

引数を指定しない場合は self を返します。引数を指定した場合 自身のコピー を生成し Exception#message 属性を error_message にして返します。

...Exception#message 属性を error_message にして返します。

Kernel.#raise は、実質的に、例外オブジェクトの exception
メソッドの呼び出しです。

@param error_message エラーメッセージを表す文字列を指定します。

//emlist[例][ruby]{
begin

# ......
...# 何か処理
rescue => e
raise e.exception("an error occurs during hogehoge process") # 詳しいエラーメッセージ
end
//}...

Thread#terminate -> self (9206.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...す。

ただし、スレッドは終了処理中(aborting)にはなりますが、
直ちに終了するとは限りません。すでに終了している場合は何もしません。このメソッドにより
終了したスレッドの Thread#value の返り値は不定です。
自身がメ...
...exit(0)
により終了します。

Kernel.#exit と違い例外 SystemExit を発生しません。

t
h1 = Thread.new do
begin

sleep 10
ensure
p "this will be displayed"
end
end

sleep 0.1
t
h1.kill

#=> "this will be displayed"

@see Kernel.#exit, Kernel.#exit!...

絞り込み条件を変える

<< 1 2 3 ... > >>