るりまサーチ

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

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

キーワード

検索結果

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

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

...template 自身のバイナリとしてパックするためのテンプレートを文字列で指定します。


以下にあげるものは、Array#pack、String#unpack
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けること...
...endian int32_t
l!<: little endian signed long
//}

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

説明中、Array#pack と String#unpack で違いのあるものは `/' で区切って
Array#pack の説明 / String#unpack の説明」としています。

: a

ASCII文字列(ヌル文字を詰...
...)
//emlist[][ruby]{
"\x01\xFE".unpack("c*") # => [1, -2]

[1, -2].pack("c*") # => "\x01\xFE"
[1, 254].pack("c*") # => "\x01\xFE"
//}

: C

unsigned char (8bit 符号なし整数)
//emlist[][ruby]{
"\x01\xFE".unpack("C*") # => [1, 254]

[1, -2].pack("C*") # => "\x01\xFE"
[1, 254].pack("C*") # =>...
...ます。
指定した場合は返値も指定した文字列オブジェクトになります。


以下にあげるものは、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
...

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

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

...ます。
指定した場合は返値も指定した文字列オブジェクトになります。


以下にあげるものは、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
...
...endian int32_t
l!<: little endian signed long
//}

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

説明中、Array#pack と String#unpack で違いのあるものは `/' で区切って
Array#pack の説明 / String#unpack の説明」としています。

: a

ASCII文字列(ヌル文字を詰...
...)
//emlist[][ruby]{
"\x01\xFE".unpack("c*") # => [1, -2]

[1, -2].pack("c*") # => "\x01\xFE"
[1, 254].pack("c*") # => "\x01\xFE"
//}

: C

unsigned char (8bit 符号なし整数)
//emlist[][ruby]{
"\x01\xFE".unpack("C*") # => [1, 254]

[1, -2].pack("C*") # => "\x01\xFE"
[1, 254].pack("C*") # =>...

Array#to_csv(**options) -> String (138.0)

CSV.generate_line(self, options) と同様です。

...ate_line(self, options) と同様です。

Array
オブジェクトを 1 行の CSV 文字列に変換するためのショートカットです。

@param options CSV.generate_line と同様のオプションを指定します。

//emlist[][ruby]{
require
'csv'

p [1, 'Matz', :Ruby, Date.new(1965...
..., 4, 14)].to_csv # => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}


@see CSV.generate_line...
...# => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}

Ruby 3.0 (CSV 3.1.9) から、次のオプションが使えるようになりました。

//emlist[][ruby]{
require
'csv'

puts [1, nil].to_...

Array#abbrev(pattern = nil) -> Hash (108.0)

self が文字列の配列の場合、self から一意に決まる短縮形を計算し、 短縮形をキー、元の文字列を値とするハッシュを返します。

...から短縮形を計算します。

Abbrev.#abbrev(self, pattern) と同じです。

@param pattern Regexp か String を指定します。


require
'abbrev'
p %w[ruby rubyist].abbrev
#=> {"ruby" => "ruby",
# "rubyi" => "rubyist",
# "rubyis" => "rubyist",
# "rubyist" =...

Array#sample -> object | nil (108.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require
'securerandom'
a = (1..10).to_a
p a.sample(random: SecureRandom) #=> 2
//}...

絞り込み条件を変える

Array#sample(n) -> Array (108.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require
'securerandom'
a = (1..10).to_a
p a.sample(random: SecureRandom) #=> 2
//}...

Array#sample(n, random: Random) -> Array (108.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require
'securerandom'
a = (1..10).to_a
p a.sample(random: SecureRandom) #=> 2
//}...

Array#sample(random: Random) -> object | nil (108.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require
'securerandom'
a = (1..10).to_a
p a.sample(random: SecureRandom) #=> 2
//}...