Sei sulla pagina 1di 7

2/6/2019 Class: Integer (Ruby 2.5.

0)

Home

(http://yoururlhere.com/)

Core 2.5.0
(http://yoururlhere.com/core-

2.5.0)

Std-lib 2.5.0

(http://yoururlhere.com/stdlib-

2.5.0)

Downloads
(http://yoururlhere.com/downloads)

Search

SPONSOR Slack — Bring your team together with Slack, the collaboration hub for work.
(http://yoururlhere.com//srv.buysellads.com/ads/click/x/GTND42QMF6BDL2JMCKY4YKQMCWAIP27ECY7DPZ3JCWBIL2JNCEAI4KJKC6BIP5QMCV7IKK3EHJNCLSIZ?
segment=placement:rubydocorg;)

Home (./index.html) Classes


(./index.html#classes) Methods Integer
(./index.html#methods)

Holds Integer (Integer.html) values. You cannot add a singleton method to an Integer (Integer.html) object, (https://srv.carbonads.net/ads/c
In Files any attempt to do so will raise a TypeError (TypeError.html). segment=placement:rubydocorg;
Bring your team together wi
bignum.c the collaboration hub for wo
numeric.c (https://srv.carbonads.net/ads/c

rational.c Constants segment=placement:rubydocorg;

ads via Carbon (http://car


utm_source=rubydocorg&utm_medium=

GMP_VERSION
Parent The version of loaded GMP.

Numeric (Numeric.html)

Public Class Methods


Methods
::sqrt (#method-c-sqrt)
#% (#method-i-25) sqrt(n) → integer
#& (#method-i-26) Returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal
#* (#method-i-2A) to the square root of n.
#** (#method-i-2A-2A)
#+ (#method-i-2B) Integer.sqrt(0) #=> 0
#- (#method-i-2D)
#-@ (#method-i-2D-40) Integer.sqrt(1) #=> 1

#/ (#method-i-2F) Integer.sqrt(24) #=> 4


#< (#method-i-3C)
#<< (#method-i-3C-3C) Integer.sqrt(25) #=> 5

#<= (#method-i-3C-3D) Integer.sqrt(10**400) #=> 10**200


#<=> (#method-i-3C-3D-3E)
#== (#method-i-3D-3D) Equivalent to Math.sqrt(n).floor, except that the result of the latter code may differ from the true value due to the
#=== (#method-i-3D-3D-3D) limited precision of floating point arithmetic.
#> (#method-i-3E)
#>= (#method-i-3E-3D)
Integer.sqrt(10**46) #=> 100000000000000000000000
#>> (#method-i-3E-3E)
#[] (#method-i-5B-5D) Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
#^ (#method-i-5E)
#abs (#method-i-abs) If n is not an Integer (Integer.html), it is converted to an Integer (Integer.html) first. If n is negative, a Math::DomainError
#allbits? (#method-i-allbits-3F) (Math/DomainError.html) is raised.
#anybits? (#method-i-anybits-3F)
#bit_length (#method-i-bit_length)
#ceil (#method-i-ceil)
#chr (#method-i-chr)
#coerce (#method-i-coerce)
Public Instance Methods
#denominator (#method-i-denominator)
#digits (#method-i-digits)
#div (#method-i-div)
#divmod (#method-i-divmod) int % other → real
#downto (#method-i-downto) Returns int modulo other.
#even? (#method-i-even-3F)
#fdiv (#method-i-fdiv) See Numeric#divmod (Numeric.html#method-i-divmod) for more information.
#floor (#method-i-floor)
#gcd (#method-i-gcd)
#gcdlcm (#method-i-gcdlcm)
int & other_int → integer
#inspect (#method-i-inspect)
Bitwise AND.
#integer? (#method-i-integer-3F)
#lcm (#method-i-lcm)
#magnitude (#method-i-magnitude)
#modulo (#method-i-modulo) int * numeric → numeric_result
#next (#method-i-next) Performs multiplication: the class of the resulting object depends on the class of numeric.
#nobits? (#method-i-nobits-3F)
#numerator (#method-i-numerator)
#odd? (#method-i-odd-3F) int ** numeric → numeric_result
#ord (#method-i-ord)
Raises int to the power of numeric, which may be negative or fractional. The result may be an Integer (Integer.html), a
#pow (#method-i-pow)
Float (Float.html), a Rational (Rational.html), or a complex number.
#pred (#method-i-pred)
#rationalize (#method-i-rationalize)
#remainder (#method-i-remainder) 2 ** 3 #=> 8

#round (#method-i-round) 2 ** -1 #=> (1/2)

https://ruby-doc.org/core-2.5.0/Integer.html 1/7
2/6/2019 Class: Integer (Ruby 2.5.0)
#size (#method-i-size) 2 ** 0.5 #=> 1.4142135623730951
#succ (#method-i-succ)
(-1) ** 0.5 #=> (0.0+1.0i)
#times (#method-i-times)
#to_f (#method-i-to_f)
#to_i (#method-i-to_i)
123456789 ** 2 #=> 15241578750190521
#to_int (#method-i-to_int)
#to_r (#method-i-to_r) 123456789 ** 1.2 #=> 5126464716.0993185
#to_s (#method-i-to_s)
123456789 ** -2 #=> (1/15241578750190521)
#truncate (#method-i-truncate)
#upto (#method-i-upto)
#| (#method-i-7C)
#~ (#method-i-~) int + numeric → numeric_result
Performs addition: the class of the resulting object depends on the class of numeric.

int - numeric → numeric_result


Files Performs subtraction: the class of the resulting object depends on the class of numeric.

grammar.en.rdoc
(./_lib/racc/rdoc/grammar_en_rdoc.html)
test.ja.rdoc (./_test/rdoc/test_ja_rdoc.html) -int → integer
contributing.rdoc (./doc/contributing_rdoc.html) Returns int, negated.
contributors.rdoc (./doc/contributors_rdoc.html)
dtrace_probes.rdoc
(./doc/dtrace_probes_rdoc.html)
int / numeric → numeric_result
extension.ja.rdoc (./doc/extension_ja_rdoc.html)
Performs division: the class of the resulting object depends on the class of numeric.
extension.rdoc (./doc/extension_rdoc.html)
globals.rdoc (./doc/globals_rdoc.html)
(https://srv.carbonads.net/ads/c
keywords.rdoc (./doc/keywords_rdoc.html)
maintainers.rdoc (./doc/maintainers_rdoc.html) int < real → true or false segment=placement:rubydocorg;

Returns true if the value of int is less than that of real. Bring your team together wi
marshal.rdoc (./doc/marshal_rdoc.html)
the collaboration hub for wo
regexp.rdoc (./doc/regexp_rdoc.html)
(https://srv.carbonads.net/ads/c
security.rdoc (./doc/security_rdoc.html)
segment=placement:rubydocorg;
standard_library.rdoc int << count → integer
(./doc/standard_library_rdoc.html) Returns int shifted left count positions, or right if count is negative. ads via Carbon (http://car
syntax.rdoc (./doc/syntax_rdoc.html) utm_source=rubydocorg&utm_medium=

assignment.rdoc
(./doc/syntax/assignment_rdoc.html)
int <= real → true or false
calling_methods.rdoc
Returns true if the value of int is less than or equal to that of real.
(./doc/syntax/calling_methods_rdoc.html)
control_expressions.rdoc
(./doc/syntax/control_expressions_rdoc.html)
exceptions.rdoc int <=> numeric → -1, 0, +1, or nil
(./doc/syntax/exceptions_rdoc.html) Comparison—Returns -1, 0, or +1 depending on whether int is less than, equal to, or greater than numeric.
literals.rdoc (./doc/syntax/literals_rdoc.html)
methods.rdoc (./doc/syntax/methods_rdoc.html) This is the basis for the tests in the Comparable (Comparable.html) module.
miscellaneous.rdoc
(./doc/syntax/miscellaneous_rdoc.html) nil is returned if the two values are incomparable.
modules_and_classes.rdoc
(./doc/syntax/modules_and_classes_rdoc.html)
precedence.rdoc int == other → true or false
(./doc/syntax/precedence_rdoc.html)
Returns true if int equals other numerically. Contrast this with Numeric#eql? (Numeric.html#method-i-eql-3F), which
refinements.rdoc
requires other to be an Integer (Integer.html).
(./doc/syntax/refinements_rdoc.html)
README.ja.rdoc
(./sample/drb/README_ja_rdoc.html) 1 == 2 #=> false
README.rdoc
1 == 1.0 #=> true
(./sample/drb/README_rdoc.html)

int == other → true or false


Class/Module Index Returns true if int equals other numerically. Contrast this with Numeric#eql? (Numeric.html#method-i-eql-3F), which
requires other to be an Integer (Integer.html).
ARGF (./ARGF.html)
ArgumentError (./ArgumentError.html)
1 == 2 #=> false
Array (./Array.html)
BasicObject (./BasicObject.html) 1 == 1.0 #=> true
Class (./Class.html)
ClosedQueueError (./ClosedQueueError.html)
Comparable (./Comparable.html) int > real → true or false
Complex (./Complex.html)
Returns true if the value of int is greater than that of real.
Complex::compatible (./Complex/compatible.html)
ConditionVariable (./ConditionVariable.html)
Continuation (./Continuation.html)
Data (./Data.html) int >= real → true or false
Dir (./Dir.html) Returns true if the value of int is greater than or equal to that of real.
ENV (./ENV.html)
EOFError (./EOFError.html)
Encoding (./Encoding.html) int >> count → integer
Encoding::CompatibilityError (./Encoding/Compat Returns int shifted right count positions, or left if count is negative.
Encoding::Converter (./Encoding/Converter.html)
Encoding::ConverterNotFoundError (./Encoding/
Encoding::InvalidByteSequenceError (./Encoding/
int[n] → 0, 1
Encoding::UndefinedConversionError (./Encoding
Bit Reference—Returns the nth bit in the binary representation of int, where int[0] is the least significant bit.
EncodingError (./EncodingError.html)
Enumerable (./Enumerable.html)
Enumerator (./Enumerator.html) a = 0b11001100101010
Enumerator::Generator (./Enumerator/Generator.ht
30.downto(0) {|n| print a[n] }
Enumerator::Lazy (./Enumerator/Lazy.html)
Enumerator::Yielder (./Enumerator/Yielder.html) #=> 0000000000000000011001100101010
Errno (./Errno.html)
Exception (./Exception.html)
FalseClass (./FalseClass.html) a = 9**15
Fiber (./Fiber.html)
50.downto(0) {|n| print a[n] }
FiberError (./FiberError.html)
File (./File.html) #=> 000101110110100000111000011110010100111100010111001
File::Constants (./File/Constants.html)

https://ruby-doc.org/core-2.5.0/Integer.html 2/7
2/6/2019 Class: Integer (Ruby 2.5.0)
File::Stat (./File/Stat.html)
int ^ other_int → integer
FileTest (./FileTest.html)
Float (./Float.html) Bitwise EXCLUSIVE OR.
FloatDomainError (./FloatDomainError.html)
FrozenError (./FrozenError.html)
GC (./GC.html) abs → integer
GC::Profiler (./GC/Profiler.html) Returns the absolute value of int.
Hash (./Hash.html)
IO (./IO.html)
(-12345).abs #=> 12345
IO::EAGAINWaitReadable (./IO/EAGAINWaitRead
IO::EAGAINWaitWritable (./IO/EAGAINWaitWritab -12345.abs #=> 12345
IO::EINPROGRESSWaitReadable (./IO/EINPROG
12345.abs #=> 12345
IO::EINPROGRESSWaitWritable (./IO/EINPROGR
IO::EWOULDBLOCKWaitReadable (./IO/EWOUL
#magnitude (Integer.html#method-i-magnitude) is an alias for #abs (Integer.html#method-i-abs).
IO::EWOULDBLOCKWaitWritable (./IO/EWOULD
IO::WaitReadable (./IO/WaitReadable.html)
IO::WaitWritable (./IO/WaitWritable.html)
IOError (./IOError.html) allbits?(mask) → true or false
IndexError (./IndexError.html) Returns true if all bits of int & mask are 1.
Integer (./Integer.html)
Interrupt (./Interrupt.html)
KeyError (./KeyError.html) anybits?(mask) → true or false
LoadError (./LoadError.html) Returns true if any bits of int & mask are 1.
LocalJumpError (./LocalJumpError.html)
Marshal (./Marshal.html)
MatchData (./MatchData.html)
bit_length → integer
Math (./Math.html)
Returns the number of bits of the value of int.
Math::DomainError (./Math/DomainError.html) (https://srv.carbonads.net/ads/c
Method (./Method.html) segment=placement:rubydocorg;
“Number of bits” means the bit position of the highest bit which is different from the sign bit (where the least
Module (./Module.html) Bring your team together wi
significant bit has bit position 1). If there is no such bit (zero or minus one), zero is returned.
Mutex (./Mutex.html) the collaboration hub for wo
NameError (./NameError.html) (https://srv.carbonads.net/ads/c
NilClass (./NilClass.html) I.e. this method returns ceil(log2(int < 0 ? -int : int+1)).
segment=placement:rubydocorg;
NoMemoryError (./NoMemoryError.html)
NoMethodError (./NoMethodError.html) ads via Carbon (http://car
(-2**1000-1).bit_length #=> 1001
utm_source=rubydocorg&utm_medium=
NotImplementedError (./NotImplementedError.htm
(-2**1000).bit_length #=> 1000
Numeric (./Numeric.html)
Object (./Object.html) (-2**1000+1).bit_length #=> 1000
ObjectSpace (./ObjectSpace.html)
(-2**12-1).bit_length #=> 13
ObjectSpace::WeakMap (./ObjectSpace/WeakMap.ht
Proc (./Proc.html) (-2**12).bit_length #=> 12
Process (./Process.html)
(-2**12+1).bit_length #=> 12
Process::GID (./Process/GID.html)
Process::Status (./Process/Status.html) -0x101.bit_length #=> 9
Process::Sys (./Process/Sys.html)
-0x100.bit_length #=> 8
Process::UID (./Process/UID.html)
Process::Waiter (./Process/Waiter.html) -0xff.bit_length #=> 8
Queue (./Queue.html)
-2.bit_length #=> 1
Random (./Random.html)
Random::Formatter (./Random/Formatter.html) -1.bit_length #=> 0
Range (./Range.html)
0.bit_length #=> 0
RangeError (./RangeError.html)
Rational (./Rational.html) 1.bit_length #=> 1
Rational::compatible (./Rational/compatible.html)
0xff.bit_length #=> 8
Regexp (./Regexp.html)
RegexpError (./RegexpError.html) 0x100.bit_length #=> 9
RubyVM (./RubyVM.html)
(2**12-1).bit_length #=> 12
RubyVM::InstructionSequence (./RubyVM/Instruct
RuntimeError (./RuntimeError.html) (2**12).bit_length #=> 13
ScriptError (./ScriptError.html)
(2**12+1).bit_length #=> 13
SecurityError (./SecurityError.html)
Signal (./Signal.html) (2**1000-1).bit_length #=> 1000
SignalException (./SignalException.html)
(2**1000).bit_length #=> 1001
SizedQueue (./SizedQueue.html)
StandardError (./StandardError.html) (2**1000+1).bit_length #=> 1001
StopIteration (./StopIteration.html)
String (./String.html) This method can be used to detect overflow in Array#pack (Array.html#method-i-pack) as follows:
Struct (./Struct.html)
Symbol (./Symbol.html)
if n.bit_length < 32
SyntaxError (./SyntaxError.html)
SystemCallError (./SystemCallError.html) [n].pack("l") # no overflow
SystemExit (./SystemExit.html)
else
SystemStackError (./SystemStackError.html)
Thread (./Thread.html) raise "overflow"
Thread::Backtrace::Location (./Thread/Backtrace/L
end
ThreadError (./ThreadError.html)
ThreadGroup (./ThreadGroup.html)
Time (./Time.html)
ceil([ndigits]) → integer or float
TracePoint (./TracePoint.html)
TrueClass (./TrueClass.html) Returns the smallest number greater than or equal to int with a precision of ndigits decimal digits (default: 0).
TypeError (./TypeError.html)
UnboundMethod (./UnboundMethod.html) When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros.
UncaughtThrowError (./UncaughtThrowError.html)
UnicodeNormalize (./UnicodeNormalize.html) Returns self when ndigits is zero or positive.
Warning (./Warning.html)
Warning::buffer (./Warning/buffer.html) 1.ceil #=> 1
ZeroDivisionError (./ZeroDivisionError.html)
1.ceil(2) #=> 1
fatal (./fatal.html)
18.ceil(-1) #=> 20

(-18).ceil(-1) #=> -10

chr([encoding]) → string
Returns a string containing the character represented by the int's value according to encoding.

https://ruby-doc.org/core-2.5.0/Integer.html 3/7
2/6/2019 Class: Integer (Ruby 2.5.0)

65.chr #=> "A"

230.chr #=> "\xE6"

255.chr(Encoding::UTF_8) #=> "\u00FF"

coerce(numeric) → array
Returns an array with both a numeric and a big represented as Bignum objects.

This is achieved by converting numeric to a Bignum.

A TypeError (TypeError.html) is raised if the numeric is not a Fixnum or Bignum type.

(0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]

denominator → 1
Returns 1.

digits → array
digits(base) → array
Returns the digits of int's place-value representation with radix base (default: 10). The digits are returned as an array
with the least significant digit as the first array element.

base must be greater than or equal to 2. (https://srv.carbonads.net/ads/c


segment=placement:rubydocorg;
Bring your team together wi
12345.digits #=> [5, 4, 3, 2, 1]
the collaboration hub for wo
12345.digits(7) #=> [4, 6, 6, 0, 5] (https://srv.carbonads.net/ads/c
segment=placement:rubydocorg;
12345.digits(100) #=> [45, 23, 1]
ads via Carbon (http://car
utm_source=rubydocorg&utm_medium=

-12345.digits(7) #=> Math::DomainError

div(numeric) → integer
Performs integer division: returns the integer result of dividing int by numeric.

divmod(numeric) → array
See Numeric#divmod (Numeric.html#method-i-divmod).

downto(limit) {|i| block } → self


downto(limit) → an_enumerator
Iterates the given block, passing in decreasing values from int down to and including limit.

If no block is given, an Enumerator (Enumerator.html) is returned instead.

5.downto(1) { |n| print n, ".. " }

puts "Liftoff!"

#=> "5.. 4.. 3.. 2.. 1.. Liftoff!"

even? → true or false


Returns true if int is an even number.

fdiv(numeric) → float
Returns the floating point result of dividing int by numeric.

654321.fdiv(13731) #=> 47.652829364212366

654321.fdiv(13731.24) #=> 47.65199646936475

-654321.fdiv(13731) #=> -47.652829364212366

floor([ndigits]) → integer or float


Returns the largest number less than or equal to int with a precision of ndigits decimal digits (default: 0).

When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros.

Returns self when ndigits is zero or positive.

1.floor #=> 1

1.floor(2) #=> 1

18.floor(-1) #=> 10

(-18).floor(-1) #=> -20

gcd(other_int) → integer
Returns the greatest common divisor of the two integers. The result is always positive. 0.gcd(x) and x.gcd(0) return
x.abs.

https://ruby-doc.org/core-2.5.0/Integer.html 4/7
2/6/2019 Class: Integer (Ruby 2.5.0)

36.gcd(60) #=> 12

2.gcd(2) #=> 2

3.gcd(-7) #=> 1

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

gcdlcm(other_int) → array
Returns an array with the greatest common divisor and the least common multiple of the two integers, [gcd, lcm].

36.gcdlcm(60) #=> [12, 180]

2.gcdlcm(2) #=> [2, 2]

3.gcdlcm(-7) #=> [1, 21]

((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]

inspect(*args)
Alias for: to_s (Integer.html#method-i-to_s)

integer? → true
Since int is already an Integer (Integer.html), this always returns true.

(https://srv.carbonads.net/ads/c
lcm(other_int) → integer segment=placement:rubydocorg;
Returns the least common multiple of the two integers. The result is always positive. 0.lcm(x) and x.lcm(0) return Bring your team together wi
zero. the collaboration hub for wo
(https://srv.carbonads.net/ads/c
segment=placement:rubydocorg;
36.lcm(60) #=> 180

ads via Carbon (http://car


2.lcm(2) #=> 2
utm_source=rubydocorg&utm_medium=

3.lcm(-7) #=> 21

((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297

magnitude → integer
Returns the absolute value of int.

(-12345).abs #=> 12345

-12345.abs #=> 12345

12345.abs #=> 12345

#magnitude (Integer.html#method-i-magnitude) is an alias for #abs (Integer.html#method-i-abs).

modulo(other) → real
Returns int modulo other.

See Numeric#divmod (Numeric.html#method-i-divmod) for more information.

next → integer
Returns the successor of int, i.e. the Integer (Integer.html) equal to int+1.

1.next #=> 2

(-1).next #=> 0

1.succ #=> 2

(-1).succ #=> 0

nobits?(mask) → true or false


Returns true if no bits of int & mask are 1.

numerator → self
Returns self.

odd? → true or false


Returns true if int is an odd number.

ord → self
Returns the int itself.

97.ord #=> 97

This method is intended for compatibility to character literals in Ruby 1.9.

For example, ?a.ord returns 97 both in 1.8 and 1.9.

pow(numeric) → numeric
pow(integer, integer) → integer

https://ruby-doc.org/core-2.5.0/Integer.html 5/7
2/6/2019 Class: Integer (Ruby 2.5.0)
Returns (modular) exponentiation as:

a.pow(b) #=> same as a**b

a.pow(b, m) #=> same as (a**b) % m, but avoids huge temporary values

pred → integer
Returns the predecessor of int, i.e. the Integer (Integer.html) equal to int-1.

1.pred #=> 0

(-1).pred #=> -2

rationalize([eps]) → rational
Returns the value as a rational. The optional argument eps is always ignored.

remainder(numeric) → real
Returns the remainder after dividing int by numeric.

x.remainder(y) means x-y*(x/y).truncate.

5.remainder(3) #=> 2

-5.remainder(3) #=> -2
(https://srv.carbonads.net/ads/c
5.remainder(-3) #=> 2 segment=placement:rubydocorg;
Bring your team together wi
-5.remainder(-3) #=> -2
the collaboration hub for wo
5.remainder(1.5) #=> 0.5 (https://srv.carbonads.net/ads/c
segment=placement:rubydocorg;
See Numeric#divmod (Numeric.html#method-i-divmod).
ads via Carbon (http://car
utm_source=rubydocorg&utm_medium=

round([ndigits] [, half: mode]) → integer or float


Returns int rounded to the nearest value with a precision of ndigits decimal digits (default: 0).

When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros.

Returns self when ndigits is zero or positive.

1.round #=> 1

1.round(2) #=> 1

15.round(-1) #=> 20

(-15).round(-1) #=> -20

The optional half keyword argument is available similar to Float#round (Float.html#method-i-round).

25.round(-1, half: :up) #=> 30

25.round(-1, half: :down) #=> 20

25.round(-1, half: :even) #=> 20

35.round(-1, half: :up) #=> 40

35.round(-1, half: :down) #=> 30

35.round(-1, half: :even) #=> 40

(-25).round(-1, half: :up) #=> -30

(-25).round(-1, half: :down) #=> -20

(-25).round(-1, half: :even) #=> -20

size → int
Returns the number of bytes in the machine representation of int (machine dependent).

1.size #=> 8

-1.size #=> 8

2147483647.size #=> 8

(256**10 - 1).size #=> 10

(256**20 - 1).size #=> 20

(256**40 - 1).size #=> 40

succ → integer
Returns the successor of int, i.e. the Integer (Integer.html) equal to int+1.

1.next #=> 2

(-1).next #=> 0

1.succ #=> 2

(-1).succ #=> 0

times {|i| block } → self


times → an_enumerator

https://ruby-doc.org/core-2.5.0/Integer.html 6/7
2/6/2019 Class: Integer (Ruby 2.5.0)
Iterates the given block int times, passing in values from zero to int - 1.

If no block is given, an Enumerator (Enumerator.html) is returned instead.

5.times {|i| print i, " " } #=> 0 1 2 3 4

to_f → float
Converts int to a Float (Float.html). If int doesn't fit in a Float (Float.html), the result is infinity.

to_i → integer
to_int → integer
Since int is already an Integer (Integer.html), returns self.

to_int (Integer.html#method-i-to_int) is an alias for to_i (Integer.html#method-i-to_i).

to_int → integer
Since int is already an Integer (Integer.html), returns self.

to_int (Integer.html#method-i-to_int) is an alias for to_i (Integer.html#method-i-to_i).

to_r → rational
Returns the value as a rational. (https://srv.carbonads.net/ads/c
segment=placement:rubydocorg;
Bring your team together wi
1.to_r #=> (1/1)
the collaboration hub for wo
(1<<64).to_r #=> (18446744073709551616/1) (https://srv.carbonads.net/ads/c
segment=placement:rubydocorg;

ads via Carbon (http://car


to_s(base=10) → string utm_source=rubydocorg&utm_medium=

Returns a string containing the place-value representation of int with radix base (between 2 and 36).

12345.to_s #=> "12345"

12345.to_s(2) #=> "11000000111001"

12345.to_s(8) #=> "30071"

12345.to_s(10) #=> "12345"

12345.to_s(16) #=> "3039"

12345.to_s(36) #=> "9ix"

78546939656932.to_s(36) #=> "rubyrules"

Also aliased as: inspect (Integer.html#method-i-inspect)

truncate([ndigits]) → integer or float


Returns int truncated (toward zero) to a precision of ndigits decimal digits (default: 0).

When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros.

Returns self when ndigits is zero or positive.

1.truncate #=> 1

1.truncate(2) #=> 1

18.truncate(-1) #=> 10

(-18).truncate(-1) #=> -10

upto(limit) {|i| block } → self


upto(limit) → an_enumerator
Iterates the given block, passing in integer values from int up to and including limit.

If no block is given, an Enumerator (Enumerator.html) is returned instead.

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

int | other_int → integer


Bitwise OR.

~int → integer
One's complement: returns a number where each bit is flipped.

Inverts the bits in an Integer (Integer.html). As integers are conceptually of infinite length, the result acts as if it had an
infinite number of one bits to the left. In hex representations, this is displayed as two periods to the left of the digits.

sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"

https://ruby-doc.org/core-2.5.0/Integer.html 7/7

Potrebbero piacerti anche