るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. rexml end_document

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

String#each_byte -> Enumerator (18133.0)

文字列の各バイトに対して繰り返します。

...文字列の各バイトに対して繰り返します。

//emlist[例][ruby]{
"str".each_byte do |byte|
p byte
end

# => 115
# => 116
# => 114

"あ".each_byte do |byte|
p byte
end

# => 227
# => 129
# => 130
//}

@see String#bytes...

String#each_byte {|byte| ... } -> self (18133.0)

文字列の各バイトに対して繰り返します。

...文字列の各バイトに対して繰り返します。

//emlist[例][ruby]{
"str".each_byte do |byte|
p byte
end

# => 115
# => 116
# => 114

"あ".each_byte do |byte|
p byte
end

# => 227
# => 129
# => 130
//}

@see String#bytes...

IO#each_byte -> Enumerator (18121.0)

IO の現在位置から 1 バイトずつ読み込み、それを整数として与え、ブロックを実行します。

...み込みメソッドとして動作します。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO.write("testfile", "aあ")
File.open("testfile") do |io|
io.each_byte { |x| p x }
# => 97
# 227
# 129
# 130
end

//}...

IO#each_byte {|ch| ... } -> self (18121.0)

IO の現在位置から 1 バイトずつ読み込み、それを整数として与え、ブロックを実行します。

...み込みメソッドとして動作します。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO.write("testfile", "aあ")
File.open("testfile") do |io|
io.each_byte { |x| p x }
# => 97
# 227
# 129
# 130
end

//}...

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

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

...いことに注意してください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

//emlist[例][ruby]{
['!'].pack('@1a', buffer: 'abc') # => "a!"
['!'].pack('@5a', buffer: 'abc') # => "abc\u0000\u0000!"
//}

@param template 自身のバイナリと...
...、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}

: エンディアン依存、整数サイズ依存 (C の構造体などに...
...ィアンの強制指定(バイナリ解析などに適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}

=== 各テンプレート文字の説明

説明中、Array#p...

絞り込み条件を変える

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

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

...いことに注意してください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

//emlist[例][ruby]{
['!'].pack('@1a', buffer: 'abc') # => "a!"
['!'].pack('@5a', buffer: 'abc') # => "abc\u0000\u0000!"
//}

@param template 自身のバイナリと...
...、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}

: エンディアン依存、整数サイズ依存 (C の構造体などに...
...ィアンの強制指定(バイナリ解析などに適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}

=== 各テンプレート文字の説明

説明中、Array#p...

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

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

...、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}

: エンディアン依存、整数サイズ依存 (C の構造体などに...
...ィアンの強制指定(バイナリ解析などに適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}

=== 各テンプレート文字の説明

説明中、Array#p...
...][ruby]{
["abc"].pack("a") # => "a"
["abc"].pack("a*") # => "abc"
["abc"].pack("a4") # => "abc\x00"

"abc\0".unpack("a4") # => ["abc\x00"]
"abc ".unpack("a4") # => ["abc "]
//}

: A

ASCII文字列(スペースを詰める/後続するヌル文字やスペースを削除)
//emlist[][ruby]{...

String#unpack(template) -> Array (637.0)

Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。

...、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}

: エンディアン依存、整数サイズ依存 (C の構造体などに...
...ィアンの強制指定(バイナリ解析などに適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}

=== 各テンプレート文字の説明

説明中、Array#p...
...][ruby]{
["abc"].pack("a") # => "a"
["abc"].pack("a*") # => "abc"
["abc"].pack("a4") # => "abc\x00"

"abc\0".unpack("a4") # => ["abc\x00"]
"abc ".unpack("a4") # => ["abc "]
//}

: A

ASCII文字列(スペースを詰める/後続するヌル文字やスペースを削除)
//emlist[][ruby]{...

Enumerator#next -> object (67.0)

「次」のオブジェクトを返します。

...mlist[例1][ruby]{
str = "xyz"
enum = str.each_byte

str.bytesize.times do
puts enum.next
end

# => 120
# 121
# 122
//}

//emlist[例2][ruby]{
str = "xyz"
enum = str.each_byte

begin
puts enum.next while true
rescue StopIteration
puts "iteration reached at end"
end

# => 12...
...121
# 122
# iteration reached at end
puts enum.next
#=> 再度 StopIteration 例外が発生
//}

//emlist[例3: Kernel.#loop は StopIteration を捕捉します。][ruby]{
str = "xyz"
enum = str.each_byte
loop do
puts enum.next
end

# => 120
# 121
# 122
//}...

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

Enumerator.new(self, method, *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]{
module Enumer...
...# 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) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)...

絞り込み条件を変える

<< 1 2 > >>