るりまサーチ

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

別のキーワード

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

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

String#hex -> Integer (18199.0)

文字列に 16 進数で数値が表現されていると解釈して整数に変換します。 接頭辞 "0x", "0X" とアンダースコアは無視されます。 文字列が [_0-9a-fA-F] 以外の文字を含むときはその文字以降を無視します。

...空文字列のときは 0 を返します。

//emlist[例][ruby]{
p
"10".hex # => 16
p
"ff".hex # => 255
p
"0x10".hex # => 16
p
"-0x10".hex # => -16

p
"xyz".hex # => 0
p
"10z".hex # => 16
p
"1_0".hex # => 16

p
"".hex # => 0
//}

@see String#oct, String#to_i, String#to_f,
K...
...ernel.#Integer, Kernel.#Float

このメソッドの逆に数値を文字列に変換するには
Kernel.#sprintf, String#%,
Integer#to_s
などを使ってください。...

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

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

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

テンプレートは
型指定文字列とその長さ(省略時は1)を並べたものです。長さと
して * が指定された時は「残りのデ...
...指定文字は以下で述べる pack テンプレート文字列の通りです。


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


以下にあげるものは、Array#pack、String#unpack
のテンプレート文字の...
...ort
i,i!: signed int
I,I!: unsigned int
l!: signed long
L!: unsigned long
q!: signed long long
Q!: unsigned long long
j,j!: intptr_t
J,J!: uintptr_t
//}

: エンディアン依存、整数サイズ非依存 (C99 の stdint.h にある厳密な幅を持つ整数型に適切)
//emlist...
...」の長さを
表します。型指定文字は以下で述べる pack テンプレート文字列の通りです。

buffer が指定されていれば、バッファとして使って返値として返します。
もし template の最初にオフセット (@) が指定されていれば、
...
...してください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

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

@param template 自身のバイナリとしてパックす...

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

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

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

テンプレートは
型指定文字列とその長さ(省略時は1)を並べたものです。長さと
して * が指定された時は「残りのデ...
...」の長さを
表します。型指定文字は以下で述べる pack テンプレート文字列の通りです。

buffer が指定されていれば、バッファとして使って返値として返します。
もし template の最初にオフセット (@) が指定されていれば、
...
...してください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

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

@param template 自身のバイナリとしてパックす...

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

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

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

@param template pack テンプレート文字列
@return オブジェクトの配列


以下にあげるもの...
...は、Array#pack、String#unpack
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けることができます。「長さ」の代わりに`*'とすることで「残り全て」
を表すこともできます。

長さの意味はテ...
...ort
i,i!: signed int
I,I!: unsigned int
l!: signed long
L!: unsigned long
q!: signed long long
Q!: unsigned long long
j,j!: intptr_t
J,J!: uintptr_t
//}

: エンディアン依存、整数サイズ非依存 (C99 の stdint.h にある厳密な幅を持つ整数型に適切)
//emlist...
...は、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けることができます。「長さ」の代わりに`*'とすることで「残り全て」
を表すこともできます。

長さ...

Kernel.#Integer(arg, base = 0, exception: true) -> Integer | nil (204.0)

引数を整数(Fixnum,Bignum)に変換した結果を返します。

...文字列以外のオブジェクトに対しては arg.to_int, arg.to_i を
この順に使用して変換します。

@param arg 変換対象のオブジェクトです。

@param base 基数として0か2から36の整数を指定します(引数argに文字列を指
定した場合...
...) です。

@param exception false を指定すると、変換できなかった場合、
例外を発生する代わりに nil を返します。

@raise ArgumentError 整数と見なせない文字列を引数に指定した場合に発生します。
@raise TypeError メソッ...
...発生します。
@raise TypeError 引数に nil を指定した場合に発生します。

//emlist[例][ruby]{
p
Integer(4) #=> 4
p
Integer(4_000) #=> 4000
p
Integer(9.88) #=> 9

p
Integer(nil) # can't convert nil into Integer (TypeError)
p
Integer(Object.new) # cannot...

絞り込み条件を変える

Encoding::Converter.new(convpath) -> Encoding::Converter (126.0)

Encoding::Converter オブジェクトを作成します。

...ェクトを作成します。

@param source_encoding 変換元のエンコーディング
@param destination_encoding 変換先のエンコーディング
@param options 変換の詳細を指定する定数やハッシュ
@param convpath 変換経路の配列

options では String#encode での...
...ュオプションに加えて、以下の定数が利用可能です。

* Encoding::Converter::INVALID_REPLACE
* Encoding::Converter::UNDEF_REPLACE
* Encoding::Converter::UNDEF_HEX_CHARREF
* Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR
* Encoding::Converter::CRLF_NEWLINE_DECORATOR...
...rue)
p
ec.convpath #=> [[#<Encoding:UTF-16BE>, #<Encoding:UTF-8>],
# "universal_newline"]

# But, if the last encoding is ASCII incompatible,
# decorators are inserted before the last conversion.
ec = Encoding::Converter.new("UTF-8", "UTF-16BE", :crlf_newline => true)
p
ec.convpath...

Encoding::Converter.new(source_encoding, destination_encoding, options) -> Encoding::Converter (126.0)

Encoding::Converter オブジェクトを作成します。

...ェクトを作成します。

@param source_encoding 変換元のエンコーディング
@param destination_encoding 変換先のエンコーディング
@param options 変換の詳細を指定する定数やハッシュ
@param convpath 変換経路の配列

options では String#encode での...
...ュオプションに加えて、以下の定数が利用可能です。

* Encoding::Converter::INVALID_REPLACE
* Encoding::Converter::UNDEF_REPLACE
* Encoding::Converter::UNDEF_HEX_CHARREF
* Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR
* Encoding::Converter::CRLF_NEWLINE_DECORATOR...
...rue)
p
ec.convpath #=> [[#<Encoding:UTF-16BE>, #<Encoding:UTF-8>],
# "universal_newline"]

# But, if the last encoding is ASCII incompatible,
# decorators are inserted before the last conversion.
ec = Encoding::Converter.new("UTF-8", "UTF-16BE", :crlf_newline => true)
p
ec.convpath...

String#to_i(base = 10) -> Integer (116.0)

文字列を 10 進数表現された整数であると解釈して、整数に変換します。

...{
p
" 10".to_i # => 10
p
"+10".to_i # => 10
p
"-10".to_i # => -10

p
"010".to_i # => 10
p
"-010".to_i # => -10
//}

整数とみなせない文字があればそこまでを変換対象とします。
変換対象が空文字列であれば 0 を返します。

//emlist[例][ruby]{
p
...
..."0x11".to_i # => 0
p
"".to_i # => 0
//}

基数を指定することでデフォルトの 10 進以外に 2 〜 36 進数表現へ変換できます。
それぞれ Ruby の整数リテラルで使用可能なプリフィクスは無視されます。
また、base に 0 を指定すると...
...uby]{
p
"01".to_i(2) # => 1
p
"0b1".to_i(2) # => 1

p
"07".to_i(8) # => 7
p
"0o7".to_i(8) # => 7

p
"1f".to_i(16) # => 31
p
"0x1f".to_i(16) # => 31

p
"0b10".to_i(0) # => 2
p
"0o10".to_i(0) # => 8
p
"010".to_i(0) # => 8
p
"0d10".to_i(0) # => 10
p
"0x10".to_i(0) # => 16
//}

@param...

Kernel.#Integer(arg, base = 0) -> Integer (104.0)

引数を整数(Fixnum,Bignum)に変換した結果を返します。

...文字列以外のオブジェクトに対しては arg.to_int, arg.to_i を
この順に使用して変換します。

@param arg 変換対象のオブジェクトです。

@param base 基数として0か2から36の整数を指定します(引数argに文字列を指
定した場合...
...TypeError メソッド to_int, to_i を持たないオブジェクトを引数に指定したか、to_int, to_i
が整数(Integerのサブクラス)を返さなかった場合に発生します。
@raise TypeError 引数に nil を指定した場合に発生します。

//emlist[例][ruby]{
p
In...
...#=> 4
p
Integer(4_000) #=> 4000
p
Integer(9.88) #=> 9

p
Integer(nil) # can't convert nil into Integer (TypeError)
p
Integer(Object.new) # cannot convert Object into Integer (TypeError)

p
Integer("10") #=> 10
p
Integer("10", 2) #=> 2
p
Integer("0d10") #=> 10
p
Integ...

String#to_f -> Float (80.0)

文字列を 10 進数表現と解釈して、浮動小数点数 Float に変換します。

...emlist[][ruby]{
p
"-10".to_f # => -10.0
p
"10e2".to_f # => 1000.0
p
"1e-2".to_f # => 0.01
p
".1".to_f # => 0.1

p
"1_0_0".to_f # => 100.0 # 数値リテラルと同じように区切りに _ を使える
p
" \n10".to_f # => 10.0 # 先頭の空白・改行は無視される
p
"7xa.5".to_f #...
...0.0 を返します。
変換対象が空文字列のケースでも、0.0 を返します。

//emlist[][ruby]{
p
"".to_f # => 0.0
p
"nan".to_f # => 0.0
p
"INF".to_f # => 0.0
p
"-Inf".to_f # => 0.0
//}

変換後の Float が有限の値を取れないときは、Float::INFINITY を用い...
...t[][ruby]{
#!ruby -W2

p
("10" * 1000).to_f # => Infinity
# warning: Float 10101010101010101010... out of range
//}

なお、このメソッドとは逆に、数値を文字列に変換するには
Kernel.#sprintf, String#%, Integer#to_s
を使用します。

@see String#hex, String#oct, String#...

絞り込み条件を変える

String#oct -> Integer (74.0)

文字列を 8 進文字列であると解釈して、整数に変換します。

...//emlist[例][ruby]{
p
"10".oct # => 8
p
"010".oct # => 8
p
"8".oct # => 0
//}

oct は文字列の接頭辞 ("0", "0b", "0B", "0x", "0X") に応じて
8 進以外の変換も行います。

//emlist[例][ruby]{
p
"0b10".oct # => 2
p
"10".oct # => 8
p
"010".oct # => 8
p
"0x10".oct # => 16...
...

//emlist[例][ruby]{
p
"-010".oct # => -8
p
"-0x10".oct # => -16
p
"-0b10".oct # => -2

p
"1_0_1x".oct # => 65
//}

@see String#hex, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float

逆に、数値を文字列に変換するにはKernel.#sprintf,
String#%, Integer#to_s...
<< 1 2 > >>