75件ヒット
[1-75件を表示]
(0.238秒)
ライブラリ
- ビルトイン (75)
キーワード
- IO (11)
- Location (11)
- NoMethodError (11)
- Queue (9)
- Status (11)
- ThreadGroup (11)
- UndefinedConversionError (11)
検索結果
先頭5件
-
Process
:: Status (8037.0) -
プロセスの終了ステータスを表すクラスです。 メソッド Process.#wait2 などの返り値として使われます。
...exited normally. status=#{$?.exitstatus}"
else
p "unknown status %#x" % $?.to_i
end
SIGCHLD を trap する例
trap(:SIGCHLD) {|sig|
puts "interrupted by signal #{sig} at #{caller[1]}"
# 複数の子プロセスの終了に対して1つの SIGCHLD しか届かない
# 場......signaled?
puts " child #{$?.pid} was killed by signal #{$?.termsig}"
if $?.coredump?
puts " child #{$?.pid} dumped core."
end
when $?.stopped?
puts " child #{$?.pid} was stopped by signal #{$?.stopsig}"
when $?.exited?
puts " chil......Process.kill :CONT, pid2
Process.kill :TERM, pid2
loop { sleep } # SIGCHLD を待つための sleep
rescue Errno::ECHILD
puts "done"
end
=> 12964
12965
interrupted by signal 17 at -:27:in `sleep'
child 12965 was stopped by signal 19
interrupt... -
NoMethodError (8013.0)
-
定義されていないメソッドの呼び出しが行われたときに発生します。
...ror)
プライベートなインスタンスメソッドを呼び出そうとした場合にも発生します。
例:
"".puts
# => NoMethodError: private method `puts' called for "":String
メソッド呼び出しの形式でなければ NameError 例外が発生します。
例:
bar... -
Thread
:: Backtrace :: Location (8013.0) -
Ruby のフレームを表すクラスです。
...a(skip)
end
def c(skip)
b(skip)
end
c(0..2).map do |call|
puts call.to_s
end
//}
例1の実行結果:
caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'
//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@......locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do |call|
puts call.to_s
end
//}
例2の実行結果:
init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'
=== 参考
* Ruby VM アドベントカレンダー #4 vm_backtrace.c: https://www.atdot.net... -
ThreadGroup (8013.0)
-
スレッドグループを表すクラスです。グループに属する Thread をまとめて 操作することができます。
...てのThreadが終了するのを待つ
5.times {
Thread.new { sleep 1; puts "#{Thread.current} finished" }
}
(ThreadGroup::Default.list - [Thread.current]).each {|th| th.join}
puts "all threads finished"
対象の Thread が Thread を起こす可能性がある... -
Encoding
:: UndefinedConversionError (8007.0) -
エンコーディング変換後の文字が存在しない場合に発生する例外。
..._encoding #=> #<Encoding:UTF-8>
p $!.destination_encoding #=> #<Encoding:EUC-JP>
p $!.source_encoding_name #=> "UTF-8"
p $!.destination_encoding_name #=> "EUC-JP"
puts $!.error_char.dump #=> "\u{a0}"
p $!.error_char.encoding #=> #<Encoding:UTF-8>
end
//}... -
IO (8007.0)
-
基本的な入出力機能のためのクラスです。
...pen('t.txt', 'w+:shift_jis:euc-jp')
f.write "\xB4\xC1\xBB\xFA" # 文字列 "漢字" の EUC-JP リテラル
f.rewind
s = f.read(4)
puts s.dump #=> "\x8A\xBF\x8E\x9A"
# エンコーディングがSJISへ変換され... -
Thread
:: Queue (8007.0) -
Queue はスレッド間の FIFO(first in first out) の通信路です。ス レッドが空のキューを読み出そうとすると停止します。キューになんら かの情報が書き込まれると実行は再開されます。
...read::SizedQueue も提供されています。
=== 例
require 'thread'
q = Queue.new
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}
th1.join
実行すると以下のように...