るりまサーチ

最速Rubyリファレンスマニュアル検索!
498件ヒット [401-498件を表示] (0.128秒)

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dsa p
  5. dsa p=

ライブラリ

モジュール

検索結果

<< < ... 3 4 5 >>

Thread::SizedQueue#shift(non_block = false) -> object (25.0)

キューからひとつ値を取り出します。 キューに push しようと待っているスレッドがあれば、実行を再開させます。

...キューからひとつ値を取り出します。
キューに push しようと待っているスレッドがあれば、実行を再開させます。

@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'...
...urce = q.pop
p
uts resource
end
end

[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}

th1.join
# => resource1
# resource2
# resource3
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop
p
uts reso...
...urce
end
end

[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}

begin
th1.join
q.pop(true)
rescue => e
p
e
p
e.message
end

# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}

@see Thread::Queue#pop...

Enumerable#slice_after {|elt| bool } -> Enumerator (19.0)

パターンがマッチした要素、もしくはブロックが真を返した要素を末尾の要素 としてチャンク化(グループ化)したものを繰り返す Enumerator を 返し ます。

...列として表現されます。そのため、以下のような呼び出しを行
う事もできます。

//emlist[例][ruby]{
enum.slice_after(pattern).each { |ary|
# ...
}
enum.slice_after { |elt| bool }.each { |ary|
# ...
}
//}

//emlist[例][ruby]{
# 偶数要素をチャンクの末尾...
..."\n", "qux\n"]
e = lines.slice_after(/(?<!\\)\n\z/)
p
e.to_a
#=> [["foo\n"], ["bar\\\n", "baz\n"], ["\n"], ["qux\n"]]
p
e.map {|ll| ll[0...-1].map {|l| l.sub(/\\\n\z/, "") }.join + ll.last }
#=>["foo\n", "barbaz\n", "\n", "qux\n"]
//}

Enumerable#map のようなメソッドを使うこともでき...

Thread::Queue#deq(non_block = false) -> object (19.0)

キューからひとつ値を取り出します。キューが空の時、呼出元のスレッドは停止します。

...@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
p
uts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(...
...r)
}

th1.join
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
p
uts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(r)
}

begin
th1.join
q.pop(true)
rescue => e
p
e
end

# => resour...
...ce1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}...

Thread::Queue#shift(non_block = false) -> object (19.0)

キューからひとつ値を取り出します。キューが空の時、呼出元のスレッドは停止します。

...@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
p
uts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(...
...r)
}

th1.join
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
p
uts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(r)
}

begin
th1.join
q.pop(true)
rescue => e
p
e
end

# => resour...
...ce1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}...

Thread#[](name) -> object | nil (13.0)

name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。

...@param name スレッド固有データのキーを文字列か Symbol で指定します。

//emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "B" },
Thread.new { Thread.current["name"] = "C" }
].each do |th|
th.join
p
uts "#{th.inspe...
...プとしては
正しく動作しません。

//emlist[][ruby]{
f = Fiber.new {
meth(1) {
Fiber.yield
}
}
meth(2) {
f.resume
}
f.resume
p
Thread.current[:name]
# => nil if fiber-local
# => 2 if thread-local (The value 2 is leaked to outside of meth method.)
//}

Fiber を切り替えて...

絞り込み条件を変える

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

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

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

@param nonblock true を与えると、キューが空の時、例外 ThreadsWait::ErrNoFinishedThread が発生します。

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

@r...
...rue でかつ、キューが空の時、発生します。

#使用例
require 'thwait'

threads = []
2.times {|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...

Zlib::Deflate#set_dictionary(string) -> String (13.0)

圧縮に用いる辞書を指定します。string を返します。 このメソッドは Zlib::Deflate.new, Zlib::ZStream#reset を呼び出した直後にのみ有効です。詳細は zlib.h を参照して下さい。

...@param string 辞書に用いる文字列を指定します。詳しくは zlib.h を参照してください。
@return 辞書に用いる文字列を返します。

require 'zlib'

def case1(str)
dez = Zlib::Deflate.new
comp_str = dez.deflate(str)
comp_str << dez.finish
comp...
..._str.size
end

def case2(str, dict)
dez = Zlib::Deflate.new
p
dez.set_dictionary(dict)
comp_str = dez.deflate(str)
comp_str << dez.finish
comp_str.size
end

i = 10
dict = 'hoge_fuga_ugougo'
sset = [ dict, 'taeagbamike', 'ugotagma', 'fugebogya' ]
g = [ 0, 1, 1, 1, 0,...
...0, 0, 3, 3, 3, 0, 0, 1, 1, 0, 0, 0, 1, 2, 2, 0, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0]
str = (1..i).collect{|m| t = rand(g.size); sset.at(g[t])}.join("")

p
rintf "%d normal:%d, dict:%d\n", i, case1(str), case2(str, dict)...

Zlib::Inflate#set_dictionary(string) -> String (13.0)

展開に用いる辞書を指定します。string を返します。 このメソッドは Zlib::NeedDict 例外が発生した直後のみ 有効です。詳細は zlib.h を参照して下さい。

...h を参照して下さい。

@param string 展開に用いる辞書を文字列で指定します。

require 'zlib'

def case2(str, dict)
dez = Zlib::Deflate.new
dez.set_dictionary(dict)
comp_str = dez.deflate(str)
comp_str << dez.finish
comp_str.size
inz = Zlib::Infla...
...te.new
begin
inz.inflate(comp_str)
rescue Zlib::NeedDict
end
# 展開に用いる辞書が必要です。
inz.set_dictionary(dict)
p
inz.inflate(comp_str)
end
dict = 'hoge_fuga_ugougo'
sset = [ dict, 'taeagbamike', 'ugotagma', 'fugebogya' ]
g = [ 0, 0, 0, 1, 1,...
...1, 0, 0, 0, 3, 3, 3, 0, 0, 1, 1,
0, 0, 0, 1, 2, 2, 0, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0]
str = g.collect{|m| sset.at(m)}.join("")

case2(str, dict)...

Array#*(times) -> Array (10.0)

配列の内容を times 回 繰り返した新しい配列を作成して返します。 値はコピーされないことに注意してください。

...とに注意してください。

@param times 繰り返したい回数を整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによ
る暗黙の型変換を試みます。

@raise TypeError 引数に整数以外の(暗...
...黙の型変換が行えない)オブジェクトを
指定した場合に発生します。

@raise ArgumentError 引数に負の数を指定した場合に発生します。

//emlist[例][ruby]{
p
[1, 2, 3] * 3 #=> [1, 2, 3, 1, 2, 3, 1, 2, 3]
//}...
<< < ... 3 4 5 >>