るりまサーチ

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

別のキーワード

  1. _builtin to_s
  2. openssl to_der
  3. openssl to_s
  4. _builtin to_a
  5. openssl to_pem

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

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

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

...れた整数であると解釈して、整数に変換します。

//emlist[例][ruby]{
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 の整数リテラルで使用可...
...例][ruby]{
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
//}

@...

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

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

...辞を含む整数表現とみなせる文字列のみ
変換します。

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

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

@param base 基数として0か2から36...
...見なせない文字列を引数に指定した場合に発生します。
@raise TypeError メソッド to_int, to_i を持たないオブジェクトを引数に指定したか、to_int, to_i
が整数(Integerのサブクラス)を返さなかった場合に発生します。
@raise TypeError...
...teger("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Integer': invalid value for Integer: "hoge" (ArgumentError)
p Integer("") # `Integer': invalid value for Integer: "" (ArgumentError)
//}

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

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

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

...辞を含む整数表現とみなせる文字列のみ
変換します。

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

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

@param base 基数として0か2から36...
...見なせない文字列を引数に指定した場合に発生します。
@raise TypeError メソッド to_int, to_i を持たないオブジェクトを引数に指定したか、to_int, to_i
が整数(Integerのサブクラス)を返さなかった場合に発生します。
@raise TypeError...
...teger("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Integer': invalid value for Integer: "hoge" (ArgumentError)
p Integer("") # `Integer': invalid value for Integer: "" (ArgumentError)
//}

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

Kernel.#caller(range) -> [String] | nil (9026.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...します。

@param range 取得したいスタックの範囲を示す Range オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel
.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end

de...
...]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p parse_caller(caller.first)
end

def bar
foo
p parse_caller(caller.first)
end

b...

Kernel.#caller(start = 1) -> [String] | nil (9026.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...します。

@param range 取得したいスタックの範囲を示す Range オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel
.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end

de...
...]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p parse_caller(caller.first)
end

def bar
foo
p parse_caller(caller.first)
end

b...

絞り込み条件を変える

Kernel.#caller(start, length) -> [String] | nil (9026.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...します。

@param range 取得したいスタックの範囲を示す Range オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel
.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end

de...
...]
を取り出して返します。

//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p parse_caller(caller.first)
end

def bar
foo
p parse_caller(caller.first)
end

b...

Object#to_int -> Integer (6108.0)

オブジェクトの Integer への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...が使われるすべての場面で代置可能であるような、
* 整数そのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_int
1
end
end

ary = [:a, :b, :c]
p(ary[Foo.new]) # => :b
//}

@see Kernel.#Integer...

String#hex -> Integer (26.0)

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

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

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

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

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

String#oct -> Integer (26.0)

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

...{
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 を使用します。...

String#to_f -> Float (26.0)

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

...# => Infinity
# warning: Float 10101010101010101010... out of range
//}

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

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

絞り込み条件を変える

Object::DATA -> File (20.0)

スクリプトの __END__ プログラムの終り以降をアクセスする File オブジェクト。

...標準入力から読みこまれなかった場合や、
__END__ で終っていない場合には定義されません。
* Kernel.#require や Kernel.#load で
読み込まれたファイルの中であってもそのファイル (__FILE__, d:spec/variables#pseudo)
ではな...
...烟花三月下揚州
孤帆遠影碧空尽
唯見長江天際流

=== 例2
sum = 0
DATA.each_line do |line|
sum += line.to_i
end

DATA.rewind
p DATA.gets # => "sum = 0¥n"

__END__
17
19
23
29
31

=== 例3
DATA.gets #...
<< 1 2 > >>