るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

キーワード

検索結果

<< 1 2 > >>

Thread::Queue#size -> Integer (23116.0)

キューの長さを返します。

...キューの長さを返します。

//emlist[例][ruby]{
q = Queue.new

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

q.length # => 4
//}...

Thread::SizedQueue#deq(non_block = false) -> object (11027.0)

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

...'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop
puts 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
puts resource
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"...

Thread::SizedQueue#pop(non_block = false) -> object (11027.0)

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

...'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop
puts 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
puts resource
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"...

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

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

...'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop
puts 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
puts resource
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"...

Thread::SizedQueue#close -> self (11015.0)

キューを close します。詳しくは Thread::Queue#close を参照してください。

...追加するスレッドを待機している場合は
ClosedQueueError が発生して中断されます。

//emlist[例][ruby]{
q = SizedQueue.new(4)

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

q.closed? # => false
q.close
q.closed? # => true
//}

@see Thread::Queue#close...

絞り込み条件を変える

Object#enum_for(method = :each, *args) -> Enumerator (8177.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2)...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (8177.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2)...

Object#to_enum(method = :each, *args) -> Enumerator (8177.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2)...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (8177.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2)...

Array#pack(template, buffer: String.new) -> String (8122.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...121].pack("cccc") # => "Ruby"
[82, 117, 98, 121].pack("c4") # => "Ruby"
[82, 117, 98, 121].pack("c*") # => "Ruby"

s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"

[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"

[82, 117, 98, 121].inject("") {|s, c| s << c}...
...}

: 文字列を数値(文字コード)の配列に変換する例
//emlist[][ruby]{
"Ruby".unpack('C*') # => [82, 117, 98, 121]

a = []
"Ruby".each_byte {|c| a << c}
a # => [82, 117, 98, 121]
//}

: "x" でヌルバイトを埋めることができる
//emlist[][ruby]{
[82, 117, 98, 121].pac...
...'socket'
official_hostname, alias_hostnames, address_family, *address_list = Socket.gethostbyname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"

"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}

: sockaddr_in...

絞り込み条件を変える

Array#pack(template) -> String (8022.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...121].pack("cccc") # => "Ruby"
[82, 117, 98, 121].pack("c4") # => "Ruby"
[82, 117, 98, 121].pack("c*") # => "Ruby"

s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"

[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"

[82, 117, 98, 121].inject("") {|s, c| s << c}...
...}

: 文字列を数値(文字コード)の配列に変換する例
//emlist[][ruby]{
"Ruby".unpack('C*') # => [82, 117, 98, 121]

a = []
"Ruby".each_byte {|c| a << c}
a # => [82, 117, 98, 121]
//}

: "x" でヌルバイトを埋めることができる
//emlist[][ruby]{
[82, 117, 98, 121].pac...
...'socket'
official_hostname, alias_hostnames, address_family, *address_list = Socket.gethostbyname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"

"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}

: sockaddr_in...
<< 1 2 > >>