Name
Integer — Integer class
Synopsis
Integer
provides common behavior of integers (Fixnum and
Bignum). Integer is an abstract
class, so you should not instantiate this class.
Inherited Class
Numeric
Included Module
Precision
Class Method
Integer::induced_from(numeric)Returns the result of converting numeric into an integer.
Instance Methods
~iBitwise operations:
AND,OR,XOR, and inversion.i&inti|inti^inti<<inti>>intBitwise left shift and right shift.
i[n]Returns the value of the
nth bit from the least significant bit, which isi[0].5[0] # => 1 5[1] # => 0 5[2] # => 1.
i.chrReturns a string containing the character for the character code
i.65.chr # => "A" ?a.chr # => "a"
i.downto(min) {|i|...}Invokes the block, decrementing each time from
itomin.3.downto(1) {|i| puts i } # prints: # 3 # 2 # 1i.nexti.succReturns the next integer following
i. Equivalent toi+ 1.i.sizeReturns the number of bytes in the machine representation of
i.i.step(upto,step) {|i|...}Iterates the block from
itoupto, incrementing bystepeach time.10.step(5, -2) {|i| puts i } # prints: # 10 # 8 # 6i.succSee
i.nexti.times {|i|...}Iterates the block
itimes.3.times {|i| puts i } # prints: # 0 # 1 # 2 .i.to_fConverts
iinto a floating point number. Float conversion may lose precision information.1234567891234567.to_f # => 1.234567891e+15
i.to_intReturns
iitself. Every object that hasto_intmethod is treated as if it’s an integer.i.upto(max) {|i|...}Invokes the block, incrementing each time from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access