ライブラリ
- English (24)
- ビルトイン (1336)
- json (12)
-
json
/ add / exception (12) -
net
/ http (60) - openssl (12)
- optparse (48)
- prettyprint (12)
- psych (27)
- readline (12)
- rexml (12)
-
rubygems
/ command (12) - shell (24)
-
shell
/ command-processor (18) -
shell
/ filter (18) - socket (72)
- strscan (84)
- syslog (48)
- thread (12)
- time (60)
- timeout (21)
- tmpdir (24)
- tracer (24)
- win32ole (24)
- zlib (192)
クラス
- Array (72)
- BasicSocket (12)
- Dir (24)
-
Encoding
:: Converter (48) -
Encoding
:: InvalidByteSequenceError (24) -
Encoding
:: UndefinedConversionError (12) - Enumerator (12)
-
Enumerator
:: ArithmeticSequence (28) - Exception (140)
- File (36)
-
File
:: Stat (12) - FrozenError (6)
-
Gem
:: Command (12) - IO (12)
- Integer (23)
-
JSON
:: State (12) - KeyError (16)
- LoadError (12)
- LocalJumpError (12)
- MatchData (48)
- Module (12)
- Mutex (2)
- NameError (22)
-
Net
:: HTTPResponse (12) - NoMethodError (12)
- Object (12)
-
OpenSSL
:: SSL :: SSLContext (12) - OptionParser (48)
- PrettyPrint (12)
- Random (36)
- Range (72)
- Regexp (36)
- Shell (24)
-
Shell
:: CommandProcessor (18) -
Shell
:: Filter (18) - SignalException (24)
- Socket (36)
- StopIteration (12)
- String (144)
- StringScanner (84)
- SystemCallError (24)
- SystemExit (24)
- Thread (72)
-
Thread
:: Mutex (10) -
Thread
:: Queue (36) -
Thread
:: SizedQueue (36) - Time (60)
- TracePoint (24)
- Tracer (24)
- UDPSocket (12)
- UNIXServer (12)
- UncaughtThrowError (33)
- WIN32OLE (24)
-
Zlib
:: GzipReader (156) -
Zlib
:: GzipWriter (24) -
Zlib
:: Inflate (12)
モジュール
- Comparable (12)
- Kernel (120)
-
Net
:: HTTPExceptions (12) -
Net
:: HTTPHeader (36) - Process (12)
- Psych (27)
- Readline (12)
- Signal (24)
- Syslog (48)
- Timeout (21)
キーワード
-
$ ERROR _ INFO (12) -
$ ERROR _ POSITION (12) -
/ (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - == (19)
- === (12)
- =~ (12)
- Fiber (12)
- Interrupt (12)
- Mutex (12)
-
NEWS for Ruby 2
. 2 . 0 (11) - ParseException (12)
- Status (12)
- Thread (12)
- [] (126)
- abort (24)
- accept (24)
-
accept
_ nonblock (12) - args (12)
- at (12)
- backtrace (12)
-
backtrace
_ locations (12) -
beginning
_ of _ line? (12) - begins? (12)
- bol? (12)
-
ca
_ file= (12) - cause (12)
-
check
_ circular? (12) - clamp (12)
- close (12)
-
connect
_ nonblock (12) - delete (12)
- deq (24)
- div (12)
- each (12)
-
each
_ byte (24) -
each
_ line (12) - end (31)
- errno (12)
-
error
_ bytes (12) -
error
_ char (12) - exception (24)
- exit (24)
- exit! (12)
-
exit
_ value (12) - fail (12)
- fetch (72)
- finish (12)
- first (24)
- format (12)
- getc (12)
- getoptlong (12)
- getpeereid (12)
- gets (12)
-
handle
_ interrupt (12) - hash (7)
- httpdate (12)
-
incomplete
_ input? (12) -
initialize
_ copy (12) - inspect (12)
- iso8601 (12)
- key (8)
- kill (12)
- last (24)
-
last
_ match (24) - lineno (12)
- load (15)
- logger (12)
- mkdir (18)
- mktmpdir (24)
- new (12)
- next (12)
- offset (24)
-
ole
_ get _ methods (12) -
ole
_ query _ interface (12) - open (36)
- open! (12)
- parse (12)
- path (12)
- peek (12)
- peep (12)
- pointer= (12)
- pop (24)
- pos= (12)
-
primitive
_ convert (48) -
public
_ constant (12) - raise (24)
-
raised
_ exception (12) - rand (36)
-
rb
_ compile _ cstr (12) -
rb
_ compile _ file (12) -
rb
_ compile _ string (12) - rdoc (12)
- read (12)
- readbyte (12)
- readchar (12)
- readline (24)
- receiver (24)
-
recvfrom
_ nonblock (12) - reject (24)
- rename (12)
- reopen (12)
- require (12)
- response (12)
- result (12)
- rfc2822 (12)
- rfc822 (12)
-
ruby 1
. 6 feature (12) -
set
_ backtrace (12) -
set
_ dictionary (12) -
set
_ get _ line _ procs (24) - setpriority (12)
- shift (24)
- signm (12)
- signo (12)
- slice (72)
- status (12)
- sticky? (12)
- success? (12)
- tag (11)
-
tcp
_ server _ loop (24) - terminate (12)
- test (18)
- throw (12)
- timeout (21)
-
to
_ json (12) -
to
_ s (35) - trap (24)
- tsort (12)
-
undef
_ system _ command (6) - ungetc (12)
- unlink (12)
- unlock (12)
- unscan (12)
- value (23)
- wrap (12)
- xmlschema (12)
- スレッド (12)
- 制御構造 (12)
検索結果
先頭5件
-
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 秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
Timeout::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
Timeout.......
@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
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])
#例
#=> 417... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (9272.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...c 秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
Timeout::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
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])
#例
#=> 417... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (9206.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...ption#backtraceに似ていますが、
Thread::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 を発生しません。
th1 = Thread.new do
begin
sleep 10
ensure
p "this will be displayed"
end
end
sleep 0.1
th1.kill
#=> "this will be displayed"
@see Kernel.#exit, Kernel.#exit!...