るりまサーチ (Ruby 2.4.0)

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

キーワード

検索結果

Integer#>(other) -> bool (78343.0)

比較演算子。数値として大きいか判定します。

比較演算子。数値として大きいか判定します。

@param other 比較対象の数値
@return self よりも other の方が小さい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 > 0 # => true
1 > 1 # => false
//}

Integer#<=>(other) -> -1 | 0 | 1 | nil (42307.0)

self と other を比較して、self が大きい時に1、等しい時に 0、小さい時 に-1、比較できない時に nil を返します。

self と other を比較して、self が大きい時に1、等しい時に 0、小さい時
に-1、比較できない時に nil を返します。

@param other 比較対象の数値
@return -1 か 0 か 1 か nil のいずれか

//emlist[][ruby]{
1 <=> 2 # => -1
1 <=> 1 # => 0
2 <=> 1 # => 1
2 <=> '' # => nil
//}

Integer#>=(other) -> bool (42307.0)

比較演算子。数値として等しいまたは大きいか判定します。

比較演算子。数値として等しいまたは大きいか判定します。

@param other 比較対象の数値
@return self よりも other の方が小さい場合か、
両者が等しい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 >= 0 # => true
1 >= 1 # => true
1 >= 2 # => false
//}

Integer#>>(bits) -> Integer (42307.0)

シフト演算子。bits だけビットを右にシフトします。

シフト演算子。bits だけビットを右にシフトします。

右シフトは、符号ビット(最上位ビット(MSB))が保持されます。
bitsが実数の場合、小数点以下を切り捨てた値でシフトします。

@param bits シフトさせるビット数

//emlist[][ruby]{
printf("%#b\n", 0b0101 >> 1) # => 0b10
p -1 >> 1 # => -1
//}

Integer#upto(max) -> Enumerator (24355.0)

self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。

...self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。

@param max 数値
@return self を返します。

//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}

@see Integer#downto, Numeric#step, Integer#times...

絞り込み条件を変える

Integer#upto(max) {|n| ... } -> Integer (24355.0)

self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。

...self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。

@param max 数値
@return self を返します。

//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}

@see Integer#downto, Numeric#step, Integer#times...

Integer#chr -> String (24343.0)

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)

p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}

引数無しで呼ばれた場合は self ...

Integer#chr(encoding) -> String (24343.0)

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)

p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}

引数無しで呼ばれた場合は self ...

Integer#div(other) -> Integer (24343.0)

整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。

...ます。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。

other が Integer オブジェクトの場合、Integer#/ の結果と一致します。

div に対応する剰余メソッドは modulo です。

@param other 二項演算の右側...
...=> 3

begin
2.div(0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
end

begin
2.div(0.0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
# Integer#/ と違い、引数が Float でもゼロで割ることはできない
end
//}

@see Integer#fdiv, Integer#/, Integer#modulo...

Integer#%(other) -> Numeric (24307.0)

算術演算子。剰余を計算します。

算術演算子。剰余を計算します。

//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}

@param other 二項演算の右側の引数(対象)
@return 計算結果

絞り込み条件を変える

Integer#&(other) -> Integer (24307.0)

ビット二項演算子。論理積を計算します。

ビット二項演算子。論理積を計算します。

@param other 数値

//emlist[][ruby]{
1 & 1 # => 1
2 & 3 # => 2
//}

Integer#*(other) -> Numeric (24307.0)

算術演算子。積を計算します。

算術演算子。積を計算します。

@param other 二項演算の右側の引数(対象)
@return 計算結果

//emlist[][ruby]{
2 * 3 # => 6
//}

Integer#**(other) -> Numeric (24307.0)

算術演算子。冪(べき乗)を計算します。

...に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//...

Integer#+(other) -> Numeric (24307.0)

算術演算子。和を計算します。

算術演算子。和を計算します。

@param other 二項演算の右側の引数(対象)
@return 計算結果

//emlist[][ruby]{
3 + 4 # => 7
//}

Integer#-(other) -> Numeric (24307.0)

算術演算子。差を計算します。

算術演算子。差を計算します。

@param other 二項演算の右側の引数(対象)
@return 計算結果

//emlist[][ruby]{
4 - 1 #=> 3
//}

絞り込み条件を変える

Integer#-@ -> Integer (24307.0)

単項演算子の - です。 self の符号を反転させたものを返します。

単項演算子の - です。
self の符号を反転させたものを返します。

//emlist[][ruby]{
- 10 # => -10
- -10 # => 10
//}

Integer#<(other) -> bool (24307.0)

比較演算子。数値として小さいか判定します。

比較演算子。数値として小さいか判定します。

@param other 比較対象の数値
@return self よりも other が大きい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 < 1 # => false
1 < 2 # => true
//}

Integer#<<(bits) -> Integer (24307.0)

シフト演算子。bits だけビットを左にシフトします。

シフト演算子。bits だけビットを左にシフトします。

@param bits シフトさせるビット数

//emlist[][ruby]{
printf("%#b\n", 0b0101 << 1) # => 0b1010
p -1 << 1 # => -2
//}

Integer#<=(other) -> bool (24307.0)

比較演算子。数値として等しいまたは小さいか判定します。

比較演算子。数値として等しいまたは小さいか判定します。

@param other 比較対象の数値
@return self よりも other の方が大きい場合か、
両者が等しい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 <= 0 # => false
1 <= 1 # => true
1 <= 2 # => true
//}

Integer#==(other) -> bool (24307.0)

比較演算子。数値として等しいか判定します。

比較演算子。数値として等しいか判定します。

@param other 比較対象の数値
@return self と other が等しい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 == 2 # => false
1 == 1.0 # => true
//}

絞り込み条件を変える

Integer#===(other) -> bool (24307.0)

比較演算子。数値として等しいか判定します。

比較演算子。数値として等しいか判定します。

@param other 比較対象の数値
@return self と other が等しい場合 true を返します。
そうでなければ false を返します。

//emlist[][ruby]{
1 == 2 # => false
1 == 1.0 # => true
//}

Integer#[](nth) -> Integer (24307.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。

@param nth 何ビット目を指すかの数値
@return 1 か 0

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.downto(0) {|n| print a[n] }
# => 00010111011010000011100001111001010011110...

Integer#^(other) -> Integer (24307.0)

ビット二項演算子。排他的論理和を計算します。

ビット二項演算子。排他的論理和を計算します。

@param other 数値

//emlist[][ruby]{
1 ^ 1 # => 0
2 ^ 3 # => 1
//}

Integer#abs -> Integer (24307.0)

self の絶対値を返します。

self の絶対値を返します。

//emlist[][ruby]{
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321
//}

Integer#bit_length -> Integer (24307.0)

self を表すのに必要なビット数を返します。

...# => 1
-1.bit_length # => 0
0.bit_length # => 0
1.bit_length # => 1
0xff.bit_length # => 8
0x100.bit_length # => 9
(2**12-1).bit_length # => 12
(2**12).bit_length # => 13
(2**12+1).bit_length # => 13
//}

@see Integer#size...

絞り込み条件を変える

Integer#ceil(ndigits = 0) -> Integer | Float (24307.0)

self と等しいかより大きな整数のうち最小のものを返します。

...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。

//emlist[][ruby]{
1.ceil # =...

Integer#denominator -> Integer (24307.0)

分母(常に1)を返します。

...分母(常に1)を返します。

@return 分母を返します。

//emlist[][ruby]{
10.denominator # => 1
-10.denominator # => 1
//}

@see Integer#numerator...

Integer#digits -> [Integer] (24307.0)

base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。

base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。

//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}

self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。

//emlist[][ruby]{
-10.digits # Math::DomainError: out of domain が発生
//}

@return 位取り記数法で表した時の数...

Integer#digits(base) -> [Integer] (24307.0)

base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。

base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。

//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}

self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。

//emlist[][ruby]{
-10.digits # Math::DomainError: out of domain が発生
//}

@return 位取り記数法で表した時の数...

Integer#divmod(other) -> [Integer, Numeric] (24307.0)

self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。

self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし
て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。

@param other self を割る数。

@see Numeric#divmod

絞り込み条件を変える

Integer#downto(min) -> Enumerator (24307.0)

self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。

...で 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。

@param min 数値
@return self を返します。

//emlist[][ruby]{
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
//}

@see Integer#upto, Numeric#step, Integer#times...

Integer#downto(min) {|n| ... } -> self (24307.0)

self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。

...で 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。

@param min 数値
@return self を返します。

//emlist[][ruby]{
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
//}

@see Integer#upto, Numeric#step, Integer#times...

Integer#even? -> bool (24307.0)

自身が偶数であれば真を返します。 そうでない場合は偽を返します。

自身が偶数であれば真を返します。
そうでない場合は偽を返します。

//emlist[][ruby]{
10.even? # => true
5.even? # => false
//}

Integer#fdiv(other) -> Numeric (24307.0)

self を other で割った商を Float で返します。 ただし Complex が関わる場合は例外です。 その場合も成分は Float になります。

...指定します。

例:

654321.fdiv(13731) # => 47.652829364212366
654321.fdiv(13731.24) # => 47.65199646936475

-1234567890987654321.fdiv(13731) # => -89910996357705.52
-1234567890987654321.fdiv(13731.24) # => -89909424858035.72
@see Numeric#quo, Numeric#div, Integer#div...

Integer#floor(ndigits = 0) -> Integer | Float (24307.0)

self と等しいかより小さな整数のうち最大のものを返します。

...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。

//emlist[][ruby]{
1.floor #...

絞り込み条件を変える

Integer#gcd(n) -> Integer (24307.0)

自身と整数 n の最大公約数を返します。

...7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
//}

また、self や n が 0 だった場合は、0 ではない方の整数の絶対値を返します。

//emlist[][ruby]{
3.gcd(0) # => 3
0.gcd(-7) # => 7
//}

@see Integer#lcm, Integer#gcdlcm...

Integer#gcdlcm(n) -> [Integer] (24307.0)

自身と整数 n の最大公約数と最小公倍数の配列 [self.gcd(n), self.lcm(n)] を返します。

...@raise ArgumentError n に整数以外のものを指定すると発生します。

//emlist[][ruby]{
2.gcdlcm(2) # => [2, 2]
3.gcdlcm(-7) # => [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1) # => [1, 4951760154835678088235319297]
//}

@see Integer#gcd, Integer#lcm...

Integer#inspect(base=10) -> String (24307.0)

整数を 10 進文字列表現に変換します。

整数を 10 進文字列表現に変換します。

引数を指定すれば、それを基数とした文字列表
現に変換します。

//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}

@return 数値の文字列表現
@param base 基数となる 2 - 36 の数値。
@raise ArgumentError base に 2 - 36 以外の数値を指定した場合に発生します。

Integer#integer? -> true (24307.0)

常に真を返します。

...常に真を返します。

//emlist[][ruby]{
1.integer? # => true
1.0.integer? # => false
//}...

Integer#lcm(n) -> Integer (24307.0)

自身と整数 n の最小公倍数を返します。

...3.lcm(-7) # => 21
((1<<31)-1).lcm((1<<61)-1) # => 4951760154835678088235319297
//}

また、self や n が 0 だった場合は、0 を返します。

//emlist[][ruby]{
3.lcm(0) # => 0
0.lcm(-7) # => 0
//}

@see Integer#gcd, Integer#gcdlcm...

絞り込み条件を変える

Integer#magnitude -> Integer (24307.0)

self の絶対値を返します。

self の絶対値を返します。

//emlist[][ruby]{
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321
//}

Integer#modulo(other) -> Numeric (24307.0)

算術演算子。剰余を計算します。

算術演算子。剰余を計算します。

//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}

@param other 二項演算の右側の引数(対象)
@return 計算結果

Integer#next -> Integer (24307.0)

self の次の整数を返します。

...self の次の整数を返します。

//emlist[][ruby]{
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
//}

@see Integer#pred...

Integer#numerator -> Integer (24307.0)

分子(常に自身)を返します。

...分子(常に自身)を返します。

@return 分子を返します。

//emlist[][ruby]{
10.numerator # => 10
-10.numerator # => -10
//}

@see Integer#denominator...

Integer#odd? -> bool (24307.0)

自身が奇数であれば真を返します。 そうでない場合は偽を返します。

自身が奇数であれば真を返します。
そうでない場合は偽を返します。

//emlist[][ruby]{
5.odd? # => true
10.odd? # => false
//}

絞り込み条件を変える

Integer#ord -> Integer (24307.0)

自身を返します。

自身を返します。

//emlist[][ruby]{
10.ord #=> 10
# String#ord
?a.ord #=> 97
//}

@see String#ord

Integer#pow(other) -> Numeric (24307.0)

算術演算子。冪(べき乗)を計算します。

...に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//...

Integer#pow(other, modulo) -> Integer (24307.0)

算術演算子。冪(べき乗)を計算します。

...に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//...

Integer#pred -> Integer (24307.0)

self から -1 した値を返します。

...self から -1 した値を返します。

//emlist[][ruby]{
1.pred #=> 0
(-1).pred #=> -2
//}

@see Integer#next...

Integer#rationalize -> Rational (24307.0)

自身を Rational に変換します。

自身を Rational に変換します。

@param eps 許容する誤差

引数 eps は常に無視されます。

//emlist[][ruby]{
2.rationalize # => (2/1)
2.rationalize(100) # => (2/1)
2.rationalize(0.1) # => (2/1)
//}

絞り込み条件を変える

Integer#rationalize(eps) -> Rational (24307.0)

自身を Rational に変換します。

自身を Rational に変換します。

@param eps 許容する誤差

引数 eps は常に無視されます。

//emlist[][ruby]{
2.rationalize # => (2/1)
2.rationalize(100) # => (2/1)
2.rationalize(0.1) # => (2/1)
//}

Integer#remainder(other) -> Numeric (24307.0)

self を other で割った余り r を返します。

.../emlist[][ruby]{
5.remainder(3) # => 2
-5.remainder(3) # => -2
5.remainder(-3) # => 2
-5.remainder(-3) # => -2

-1234567890987654321.remainder(13731) # => -6966
-1234567890987654321.remainder(13731.24) # => -9906.22531493148
//}

@see Integer#divmod, Integer#modulo, Numeric#modulo...

Integer#round(ndigits = 0, half: :up) -> Integer | Float (24307.0)

self ともっとも近い整数を返します。

...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の値の...

Integer#size -> Integer (24307.0)

整数の実装上のサイズをバイト数で返します。

...整数の実装上のサイズをバイト数で返します。

//emlist[][ruby]{
p 1.size # => 8
p 0x1_0000_0000.size # => 8
//}

@see Integer#bit_length...

Integer#succ -> Integer (24307.0)

self の次の整数を返します。

...self の次の整数を返します。

//emlist[][ruby]{
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
//}

@see Integer#pred...

絞り込み条件を変える

Integer#times -> Enumerator (24307.0)

self 回だけ繰り返します。 self が正の整数でない場合は何もしません。

...れます。

//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
//}

@see Integer#upto, Integer#downto, Numeric#step...

Integer#times {|n| ... } -> self (24307.0)

self 回だけ繰り返します。 self が正の整数でない場合は何もしません。

...れます。

//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
//}

@see Integer#upto, Integer#downto, Numeric#step...

Integer#to_f -> Float (24307.0)

self を浮動小数点数(Float)に変換します。

self を浮動小数点数(Float)に変換します。

self が Float の範囲に収まらない場合、Float::INFINITY を返します。

//emlist[][ruby]{
1.to_f # => 1.0
(Float::MAX.to_i * 2).to_f # => Infinity
(-Float::MAX.to_i * 2).to_f # => -Infinity
//}

Integer#to_i -> self (24307.0)

self を返します。

self を返します。

//emlist[][ruby]{
10.to_i # => 10
//}

Integer#to_int -> self (24307.0)

self を返します。

self を返します。

//emlist[][ruby]{
10.to_i # => 10
//}

絞り込み条件を変える

Integer#to_r -> Rational (24307.0)

自身を Rational に変換します。

自身を Rational に変換します。

//emlist[][ruby]{
1.to_r # => (1/1)
(1<<64).to_r # => (18446744073709551616/1)
//}

Integer#to_s(base=10) -> String (24307.0)

整数を 10 進文字列表現に変換します。

整数を 10 進文字列表現に変換します。

引数を指定すれば、それを基数とした文字列表
現に変換します。

//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}

@return 数値の文字列表現
@param base 基数となる 2 - 36 の数値。
@raise ArgumentError base に 2 - 36 以外の数値を指定した場合に発生します。

Integer#truncate(ndigits = 0) -> Integer | Float (24307.0)

0 から self までの整数で、自身にもっとも近い整数を返します。

...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。

//emlist[][ruby]{
1.truncate...

Integer#|(other) -> Integer (24307.0)

ビット二項演算子。論理和を計算します。

ビット二項演算子。論理和を計算します。

@param other 数値

//emlist[][ruby]{
1 | 1 # => 1
2 | 3 # => 3
//}

Integer#~ -> Integer (24307.0)

ビット演算子。否定を計算します。

ビット演算子。否定を計算します。

//emlist[][ruby]{
~1 # => -2
~3 # => -4
~-4 # => 3
//}

絞り込み条件を変える