Ruby 1.9.0 > Home > All Libraries > library _builtin > class Integer

class Integer

ancestors: Integer < Precision < Numeric < Comparable < Object < Kernel < BasicObject

Abstract

整数の抽象クラス。サブクラスとして FixnumBignum があり ます。この 2 種類の整数は値の大きさに応じてお互いに自動的に変換されま す。ビット操作において整数は無限の長さのビットストリングとみなすことが できます。

Singleton Methods

signaturedescription
induced_from(num) -> Integer

num を Integer に変換した結果を返します。 引数が数値の場合は小数部が切り捨てられ、そうでない場合はTypeErrorをraiseします。

Instance Methods

signaturedescription
%(other) -> Fixnum | Bignum | Float

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

&(other) -> Fixnum | Bignum

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

*(other) -> Fixnum | Bignum | Float

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

**(other)

べき乗。

rational
**(other) -> Fixnum | Bignum | Float

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

+(other) -> Fixnum | Bignum | Float

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

-(other) -> Fixnum | Bignum | Float

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

/(other)

除算。

rational
/(other) -> Fixnum | Bignum | Float

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

<(other) -> bool

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

<<(bits) -> Fixnum | Bignum

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

<=(other) -> bool

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

<=>(other) -> Fixnum

self と other を比較して、self が大きい時に正、 等しい時に 0、小さい時に負の整数を返します。

==(other) -> bool

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

>(other) -> bool

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

>=(other) -> bool

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

>>(bits) -> Fixnum | Bignum

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

[](nth) -> Fixnum

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

^(other) -> Fixnum | Bignum

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

chr -> String

文字コードに対応する 1 バイトの文字列を返します。

downto(min) {|n| ... } -> self
downto(min) -> Enumerable::Enumerator

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

even? -> bool

self が偶数であれば真を返します。

integer? -> true

常に真を返します。

next -> Fixnum | Bignum
succ -> Fixnum | Bignum

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

odd? -> bool

self が奇数であれば真を返します。

ord -> Integer

Returns the int itself.

pred -> Integer

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

size -> Fixnum

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

step(limit, step) {|n| ... } -> self

self からはじめ step を足しながら limit を越える 前までブロックを繰り返します。step は負の数も指定できます。 また、limit や step には Float なども指定できます。

times {|n| ... } -> self
times -> Enumerable::Enumerator

self 回だけ(0 から self-1 まで)繰り返します。 self が負であれば何もしません。

to_f -> Float

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

to_i -> self
to_int -> self

self を返します。

to_s -> String
to_s(base) -> String

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

upto(max) {|n| ... } -> Fixnum | Bignum
upto(max) -> Enumerable::Enumerator

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

|(other) -> Fixnum | Bignum

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

~ -> Fixnum | Bignum

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

Inherited Methods

! != +@ -@ abs arg ceil clone coerce conj div divmod eql? fdiv floor im imag modulo nonzero? real remainder round scalar? truncate zero? === =~ __id__ __send__ _dump class dclone display enum_for equal? extend freeze frozen? hash initialize initialize_copy inspect instance_eval instance_exec instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? marshal_dump marshal_load method method_missing methods nil? pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods public_methods remove_instance_variable respond_to? singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? tap to_a to_ary to_hash to_io to_proc to_regexp to_splat to_str to_yaml to_yaml_properties to_yaml_style untaint .new

Added Methods

signaturedescriptionlibrary
denominator

In an integer, the denominator is 1. Therefore, this method returns 1.

rational
from_prime_division(pd)

素因数分解の配列 pd から数を求めます。 pd は [素因数, 指数] 組の配列です。

mathn
gcd(n)

self と n の最大公約数を Fixnum として返す。 self や n が負の場合は、正に変換してから計算する。

rational
gcd2(int)

self と int の最大公約数を求めます。

mathn
gcdlcm(int)

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

rational
lcm(n)

self と n の最小公倍数を返す。 self や n が負の場合は、正に変換してから計算する。

rational
numerator

In an integer, the value is the numerator of its rational equivalent. Therefore, this method returns self.

rational
power!(other)

rationalで再定義される前のInteger#**の別名。 other が正または 0 の整数 (Integer) ならば、 整数 (Integer) を、それ以外なら、浮動小数 (Float) を返す。

rational
prime_division

self の素因数分解(の配列)を求めます。

mathn
to_r

対応する有理数 (Rational) を返す。 Rational(self, 1) と同じ。

rational