るりまサーチ

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

別のキーワード

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

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

ThreadGroup#add(thread) -> self (21109.0)

スレッド thread が属するグループを自身に変更します。

...ープを自身に変更します。

@param thread 自身に加えたいスレッドを指定します。

@raise ThreadError 自身が freeze されているか enclose されている場合に、発生します。また引数 thread が属する ThreadGroup が freeze されているか enclose...
...ruby]{
p
uts "Initial group is #{ThreadGroup::Default.list}"
# => Initial group is [#<Thread:0x4a49168 run>]

tg = ThreadGroup.new
t1 = Thread.new { sleep }
t2 = Thread.new { sleep }
p
uts "t1 is #{t1}" # => t1 is #<Thread:0x50bef60>
p
uts "t2 is #{t2}" # => t2 is #<Thread:0x50beed0>
tg.add(t1)
p
uts "I...
...nitial group now #{ThreadGroup::Default.list}"
# => Initial group now [#<Thread:0x3039168 run>, #<Thread:0x50beed0 run>]
p
uts "tg group now #{tg.list}"
# => tg group now [#<Thread:0x50bef60 run>]
//}...

Thread#add_trace_func(pr) -> Proc (6315.0)

スレッドにトレース用ハンドラを追加します。

...す。

@param pr トレースハンドラ(Proc オブジェクト)

//emlist[例][ruby]{
th = Thread.new do
class Trace
end
43.to_s
end
th.add_trace_func lambda {|*arg| p arg }
th.join

# => ["line", "example.rb", 4, nil, #<Binding:0x00007f98e107d0d8>, nil]
# => ["c-call", "example.rb", 4, :i...
...ple.rb", 4, :inherited, #<Binding:0x00007f98e1085d00>, Class]
# => ["class", "example.rb", 4, nil, #<Binding:0x00007f98e108f210>, nil]
# => ["end", "example.rb", 5, nil, #<Binding:0x00007f98e108e5e0>, nil]
# => ["line", "example.rb", 6, nil, #<Binding:0x00007f98e108d4b0>, nil]
# => ["c-call", "examp...
...le.rb", 6, :to_s, #<Binding:0x00007f98e1097aa0>, Integer]
# => ["c-return", "example.rb", 6, :to_s, #<Binding:0x00007f98e1095cc8>, Integer]
//}

@see Thread#set_trace_func Kernel.#set_trace_func...

ThreadGroup (6008.0)

スレッドグループを表すクラスです。グループに属する Thread をまとめて 操作することができます。

...は ThreadGroup::Default に属します。

: 例:

生成したすべてのThreadが終了するのを待つ

5.times {
Thread.new { sleep 1; puts "#{Thread.current} finished" }
}

(ThreadGroup::Default.list - [Thread.current]).each {|th| th.join}

p
uts "all threads...
...Thread.exclusive参照)

Thread.exclusive do
(ThreadGroup::Default.list - [Thread.current]).each {|th| th.join}
end

=== ThreadGroup#freeze と ThreadGroup#enclose の違い

どちらのメソッドでも ThreadGroup#add によるスレッドの追加ができなくなる点は同じ...
...する ThreadGroup が freeze
されている場合、Thread.new{ ... } はエラーになります。ThreadGroup が enclose されているだけでは、
Thread.new{ ... } はエラーになりません。生成されたスレッドは従来通り 親スレッドの ThreadGroup に属します...

ThreadGroup.new -> ThreadGroup (3114.0)

新たな ThreadGroup を生成して返します。

...p を生成して返します。

//emlist[例][ruby]{
thread_group = ThreadGroup.new
thread_group.add Thread.new { sleep 0.1; Thread.new { sleep 1 }; sleep 1 }
thread_group.add Thread.new { sleep 2 }
sleep 0.5
thread_group.list # => [#<Thread:0x007fc6f1842d70 sleep>, #<Thread:0x007fc6f1842c80 sleep...
...>, #<Thread:0x007fc6f080dba8 sleep>]
//}...

ThreadGroup#enclose -> self (3048.0)

自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。 enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。

...自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。
enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。

ただし、Thread.new によるスレッドの追加は禁止されません。enclose されたスレッ...
...thg = ThreadGroup.new.enclose
thg.add Thread.new {}

=> -:2:in `add': can't move to the enclosed thread group (ThreadError)

削除の例:

thg1 = ThreadGroup.new
thg2 = ThreadGroup.new

th = Thread.new {sleep 1}

thg1.add th
thg1.enclose
thg2.add th

=> -:8:in `add': can't move fr...
...om the enclosed thread group (ThreadError)...

絞り込み条件を変える

String#center(width, padding = &#39; &#39;) -> String (250.0)

長さ width の文字列に self を中央寄せした文字列を返します。 self の長さが width より長い時には元の文字列の複製を返します。 また、第 2 引数 padding を指定したときは 空白文字の代わりに padding を詰めます。

... padding を指定したときは
空白文字の代わりに padding を詰めます。

@param width 返り値の文字列の最小の長さ
@param padding 長さが width になるまで self の両側に詰める文字

//emlist[例][ruby]{
p
"foo".center(10) # => " foo "
p
"f...
...oo".center(9) # => " foo "
p
"foo".center(8) # => " foo "
p
"foo".center(7) # => " foo "
p
"foo".center(3) # => "foo"
p
"foo".center(2) # => "foo"
p
"foo".center(1) # => "foo"
p
"foo".center(10, "*") # => "***foo****"
//}

@see String#ljust, String...

String#ljust(width, padding = &#39; &#39;) -> String (238.0)

長さ width の文字列に self を左詰めした文字列を返します。 self の長さが width より長い時には元の文字列の複製を返します。 また、第 2 引数 padding を指定したときは 空白文字の代わりに padding を詰めます。

... padding を指定したときは
空白文字の代わりに padding を詰めます。

@param width 返り値の文字列の最小の長さ
@param padding 長さが width になるまで self の右側に詰める文字

//emlist[例][ruby]{
p
"foo".ljust(10) # => "foo "
p
"f...
...oo".ljust(9) # => "foo "
p
"foo".ljust(8) # => "foo "
p
"foo".ljust(2) # => "foo"
p
"foo".ljust(1) # => "foo"
p
"foo".ljust(10, "*") # => "foo*******"
//}

@see String#center, String#rjust...

String#rjust(width, padding = &#39; &#39;) -> String (238.0)

長さ width の文字列に self を右詰めした文字列を返します。 self の長さが width より長い時には元の文字列の複製を返します。 また、第 2 引数 padding を指定したときは 空白文字の代わりに padding を詰めます。

... padding を指定したときは
空白文字の代わりに padding を詰めます。

@param width 返り値の文字列の最小の長さ
@param padding 長さが width になるまで self の左側に詰める文字

//emlist[例][ruby]{
p
"foo".rjust(10) # => " foo"
p
"f...
...oo".rjust(9) # => " foo"
p
"foo".rjust(8) # => " foo"
p
"foo".rjust(2) # => "foo"
p
"foo".rjust(1) # => "foo"
p
"foo".rjust(10, "*") # => "*******foo"
//}

@see String#center, String#ljust...

Thread#set_trace_func(pr) -> Proc | nil (214.0)

スレッドにトレース用ハンドラを設定します。

...bda {|*arg| p arg }
th.join

# => ["line", "example.rb", 2, nil, #<Binding:0x00007fc8de87cb08>, nil]
# => ["c-call", "example.rb", 2, :inherited, #<Binding:0x00007fc8de886770>, Class]
# => ["c-return", "example.rb", 2, :inherited, #<Binding:0x00007fc8de8844e8>, Class]
# => ["class", "example.rb", 2,...
...c8de88e830>, nil]
# => ["end", "example.rb", 3, nil, #<Binding:0x00007fc8de88d6b0>, nil]
# => ["line", "example.rb", 4, nil, #<Binding:0x00007fc8de88c440>, nil]
# => ["c-call", "example.rb", 4, :to_s, #<Binding:0x00007fc8de896f30>, Integer]
# => ["c-return", "example.rb", 4, :to_s, #<Binding:0x00007...
..., Integer]
# => ["line", "example.rb", 5, nil, #<Binding:0x00007fc8de967b08>, nil]
# => ["c-call", "example.rb", 5, :current, #<Binding:0x00007fc8de967798>, Thread]
# => ["c-return", "example.rb", 5, :current, #<Binding:0x00007fc8de9673b0>, Thread]
# => ["c-call", "example.rb", 5, :set_trace_func, #...

Hash.[](other) -> Hash (67.0)

新しいハッシュを生成します。 引数otherと同一のキーと値を持つ新たなハッシュを生成して返します。

...す。

@param other 生成元となるハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。

//emlist[][ruby]{
h = {1 => "value"}
h.default = "none"

g = Hash[h]
p
g #=> {1=>"value"}

p
h[:no] #=> "none"
p
g[:no] #=> nil

h[:add] = "some"
p
h #=> {1=...
...>"value", :add=>"some"}
p
g #=> {1=>"value"}

h[1] << 'plus' #破壊的操作
p
h #=> {1=>"valueplus", :add=>"some"}
p
g #=> {1=>"valueplus"}
//}...

絞り込み条件を変える

<< 1 2 > >>