108件ヒット
[1-100件を表示]
(0.051秒)
キーワード
- ArgumentError (11)
- BasicObject (11)
- Complex (11)
- ConditionVariable (9)
- Encoding (11)
- Location (11)
- Method (11)
- Thread (11)
- Tms (11)
- TypeError (11)
検索結果
-
Thread
:: ConditionVariable (93.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...。@q が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。
require 'thread'
class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex......= Mutex.new
@q = []
end
def count
@q.size
end
def enq(v)
@mutex.synchronize{
@full.wait(@mutex) if count == @max
@q.push v
@empty.signal if count == 1
}
end
def deq
@mutex.synchronize{
@empty.wait(@mutex) if co......unt == 0
v = @q.shift
@full.signal if count == (@max - 1)
v
}
end
alias send enq
alias recv deq
end
if __FILE__ == $0
q = TinyQueue.new(1)
foods = 'Apple Banana Strawberry Udon Rice Milk'.split
l = []
th = Thread.new {
for obj in... -
BasicObject (15.0)
-
特殊な用途のために意図的にほとんど何も定義されていないクラスです。 Objectクラスの親にあたります。Ruby 1.9 以降で導入されました。
...合にだけ BasicObject から派生してください。
=== 例
//emlist[例][ruby]{
class Proxy < BasicObject
def initialize(target)
@target = target
end
def method_missing(message, *args)
@target.__send__(message, *args)
end
end
proxy = Proxy.new("1")
proxy.to_i #=> 1
//}... -
Complex (15.0)
-
複素数を扱うクラスです。
...x('2/3+3/4i') # => ((2/3)+(3/4)*i)
Complex('1@2') # => (-0.4161468365471424+0.9092974268256817i)
3.to_c # => (3+0i)
0.3.to_c # => (0.3+0i)
'0.3-0.5i'.to_c # => (0.3-0.5i)
'2/3+3/4i'.to_c # => ((2/3)+(3/4)*i)
'1@2'.to_c # => (-0.4161468365471424+0.... -
ArgumentError (9.0)
-
引数の数があっていないときや、数は合っていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。
...、数は合っていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。
例:
Time.at # => wrong number of arguments (0 for 1) (ArgumentError)
Array.new(-1) # => negative array size (ArgumentError)
など
@see TypeError......ていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。
例:
Time.at # => wrong number of arguments (given 0, expected 1..2) (ArgumentError)
Array.new(-1) # => negative array size (ArgumentError)
など
@see TypeError... -
Encoding (9.0)
-
文字エンコーディング(文字符号化方式)のクラスです。Rubyの多言語対応(M17N)機能において利用されます。
...ンコーディングによるものであるかも併せて保持しています。この情報は String#encoding により取得できます。 Encoding オブジェクトを返すメソッドにはこの他に IO#internal_encoding, IO#external_encoding などがあります。
@see spec/m17n... -
Method (9.0)
-
Object#method によりオブジェクト化され たメソッドオブジェクトのクラスです。
...、Method は大規模コードに向くと言えます。
既存のメソッドを Method オブジェクト化する。
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m = Foo.new.method(:foo)
p m # => #<Method: Foo#foo>
p m.call(1) # =......cc>
p pr.call(1) # => "proc called with arg 1"
//}
Method オブジェクトが有用なのは以下のような場合。
//emlist[例][ruby]{
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
obj = Foo.new
# 任意のキーとメソッドの関係をハッシュ......(Method オブジェクトはレシーバを保持する)必
要がないなら Object#public_sendを使う方法も有用。
//emlist[例][ruby]{
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
# 任意のキーとメソッド(の名前)の関係をハッシュに... -
Process
:: Tms (9.0) -
Process.#times の返り値を表現する構造体です。
...Process.#times の返り値を表現する構造体です。
この機能がサポートされているプラットフォーム上でプロセスの
処理時間に関する情報を保持します。プラットフォームによっては
使えない値があります。
@see Process.#times... -
Thread (9.0)
-
スレッドを表すクラスです。スレッドとはメモリ空間を共有して同時に実行される制御の流れです。 Thread を使うことで並行プログラミングが可能になります。
...ill 等で終了したスレッドはこの状態になります。この状
態のスレッドはどこからも参照されていなければ GC によりメモリ上から
なくなります。
この状態のスレッドは「死んで」います。
=== デッドロックの検出
@todo... -
Thread
:: Backtrace :: Location (9.0) -
Ruby のフレームを表すクラスです。
...r_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の... -
TypeError (9.0)
-
メソッドの引数に期待される型ではないオブジェクトや、期待される振る舞いを持たないオブジェクトが渡された時に発生します。
...メソッドの引数に期待される型ではないオブジェクトや、期待される振る舞いを持たないオブジェクトが渡された時に発生します。
@see ArgumentError...