93件ヒット
[1-93件を表示]
(0.017秒)
別のキーワード
検索結果
先頭5件
-
Array
# pack(template) -> String (13.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文字列(ヌル文字を詰......ong(その2)
//emlist[][ruby]{
s = "\xFF\xFF\xFF\xFE"
n = s.unpack("N").pack("l").unpack("l")[0]
n # => -2
//}
: IPアドレス
//emlist[][ruby]{
require 'socket'
official_hostname, alias_hostnames, address_family, *address_list = Socket.gethostbyname("localhost")
address_list.find {|address| addre......ます。
指定した場合は返値も指定した文字列オブジェクトになります。
以下にあげるものは、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を... -
Array
# pack(template , buffer: String . new) -> String (13.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文字列(ヌル文字を詰......ong(その2)
//emlist[][ruby]{
s = "\xFF\xFF\xFF\xFE"
n = s.unpack("N").pack("l").unpack("l")[0]
n # => -2
//}
: IPアドレス
//emlist[][ruby]{
require 'socket'
official_hostname, alias_hostnames, address_family, *address_list = Socket.gethostbyname("localhost")
address_list.find {|address| addre... -
Array
# to _ csv(**options) -> String (13.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......=> "1 Matz Ruby 1965-04-14\r\n"
//}
Ruby 3.0 (CSV 3.1.9) から、次のオプションが使えるようになりました。
//emlist[][ruby]{
require 'csv'
puts [1, nil].to_csv # => 1,
puts [1, nil].to_csv(write_nil_value: "N/A") # => 1,N/A
puts [2, ""].to_csv... -
Array
# abbrev(pattern = nil) -> Hash (7.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 (7.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 (7.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 (7.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 (7.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
# to _ csv(**options) -> String (7.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...