るりまサーチ

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

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. csv to_i
  5. kernel $-i

ライブラリ

クラス

キーワード

検索結果

Matrix.empty(row_size=0, column_size=0) -> Matrix (21325.0)

要素を持たない行列を返します。

...ize 、 column_size のいずれか一方は0である必要があります。

//emlist[例][ruby]{
require 'matrix'
m = Matrix.empty(2, 0)
m == Matrix[ [], [] ]
# => true
n = Matrix.empty(0, 3)
n == Matrix.columns([ [], [], [] ])
# => true
m * n
# => Matrix[[0, 0, 0], [0, 0, 0]]
//}

@param row_si...
...ze 行列の行数
@param column_size 行列の列数
@raise ArgumentError row_size, column_size が両方とも0でない場合に発生します...

ThreadsWait#empty? -> bool (9125.0)

同期されるスレッドが存在するならば true をかえします。

...ッドが存在するならば true をかえします。

使用例
require 'thwait'

threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}

thall = ThreadsWait.new
p thall.threads.empty? #=> true
thall.join(*threads)
p thall.threads.empty? #=> false...

ThreadsWait#next_wait(nonblock = nil) -> Thread (9124.0)

指定したスレッドのどれかが終了するまで待ちます。

...ait::ErrNoFinishedThread が発生します。

@raise ErrNoWaitingThread 終了をまつスレッドが存在しない時、発生します。

@raise ErrNoFinishedThread nonblock がtrue でかつ、キューが空の時、発生します。

#使用例
require 'thwait'

threads = []
2.tim...
...es {|i|
threads << Thread.new { sleep i }
}

thall = ThreadsWait.new
thall.join_nowait(*threads)
until thall.empty?
th = thall.next_wait
p th
end

@see Queue#pop...

MonitorMixin (6036.0)

スレッドの同期機構としてのモニター機能を提供するモジュールです。

...ラスに Module#include したり、オブジェクトに
Object#extend したりすることでそのクラス/オブジェクトに
モニタ機能を追加します。

=== 例

//emlist[消費者、生産者問題の例][ruby]{
require 'monitor'

buf = []
buf.extend(MonitorMixin) # 配列にモ...
...
empty
_cond = buf.new_cond # 配列が空であるかないかを通知する条件変数

# consumer
Thread.start do
loop do
buf.synchronize do # ロックする
empty
_cond.wait_while { buf.empty? } # 配列が空である間はロックを開放して待つ
print buf.shift #...
...# producer
while line = ARGF.gets
buf.synchronize do # ロックする
buf.push(line) # 配列を変更(追加)
empty
_cond.signal # 配列に要素が追加されたことを条件変数を通して通知
end # ここでロックを開放
end
//}

=== 初期化

MonitorMixin は初期...

Monitor (6030.0)

スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。

...onitorMixin を include し、いくつかの別名を定義したクラスです。

=== 例

//emlist[消費者、生産者問題の例][ruby]{
require 'monitor'

buf = []
mon = Monitor.new
empty
_cond = mon.new_cond

# consumer
Thread.start do
loop do
mon.synchronize do
empty
_cond.wait...
...hile { buf.empty? }
print buf.shift
end
end
end

# producer
while line = ARGF.gets
mon.synchronize do
buf.push(line)
empty
_cond.signal
end
end
//}

2回ロックしてもデッドロックにならない例です。

//emlist[デッドロックにならない例][ruby]{
requi...
...re 'monitor'
mon = Monitor.new
mon.synchronize {
mon.synchronize {
}
}
//}

Thread::Mutex ではデッドロックになります。

//emlist[Mutex でデッドロックになる例][ruby]{
mx = Mutex.new
mx.synchronize {
mx.synchronize {
}
}
# => deadlock; recursive locking (ThreadError)
/...

絞り込み条件を変える

Thread::ConditionVariable (6030.0)

スレッドの同期機構の一つである状態変数を実現するクラスです。

...一つである状態変数を実現するクラスです。

以下も ConditionVariable を理解するのに参考になります。

https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとしま...
...に 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...
...nize{
@full.wait(@mutex) if count == @max
@q.push v
@empty.signal if count == 1
}
end

def deq
@mutex.synchronize{
@empty.wait(@mutex) if count == 0
v = @q.shift
@full.signal if count == (@max - 1)
v
}
end

ali...

optparse (96.0)

コマンドラインのオプションを取り扱うためのライブラリです。

...(1) OptionParser オブジェクト opt を生成する。
(2) オプションを取り扱うブロックを opt に登録する。
(3) opt.parse(ARGV) でコマンドラインを実際に parse する。

というような流れになります。

* optiondef
* optionarg
* longoption
* hel...
..." [" を付けます。

//emlist[sample.rb][ruby]{
require 'optparse'
opt = OptionParser.new

opt.on('-a [VAL]') {|v| p v } # <- [VAL] を追加
opt.on('-b') {|v| p v }

opt.parse!(ARGV)
p ARGV
//}

ruby sample.rb -a

# => nil
[]


同様に、ヘルプの見...
...d: #{k}"
exit 1
}
subparsers['add'] = OptionParser.new.on('-i') { puts "add -i" }
subparsers['del'] = OptionParser.new.on('-i') { puts "del -i" }
subparsers['list'] = OptionParser.new.on('-i') { puts "list -i" }

parser.order!(ARGV)
subparsers[ARGV.shift].parse!(ARGV) unless ARGV.empty?
//}

...

ruby 1.8.3 feature (30.0)

ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))

...変更
* [api]: 拡張ライブラリ API
* [lib]: ライブラリ
* レベル
* [bug]: バグ修正
* [new]: 追加されたクラス/メソッドなど
* [compat]: 変更されたクラス/メソッドなど
* 互換性のある変更
* only backward-compatibility
* 影...
...join
p $SAFE
Hoge.new.foo

$ ruby-1.8.2 mthd_taint.rb
0
"safe level: 0"

$ ruby-1.8.3 mthd_taint.rb
0
mthd_taint.rb:11:in `foo': calling insecure method: foo (SecurityError)
from mthd_taint.rb:11

=== 2005-09-09
: String#* [ruby] [compat]
: String#[]...
...-e: invalid name for global variable - --foo@bar (NameError)

=== 2005-04-18
: WIN32OLE.codepage [lib] [new]
: WIN32OLE.codepage= [lib] [new]

=== 2005-04-10
: WIN32OLE#invoke [lib] [bug]
nil を VT_ERROR に変換して Invokeを呼び出して失敗するときには VT_EMPTYに変換...