Class: Integer

Inherits:
Numeric show all
Includes:
Precision
Defined in:
numeric.c,
numeric.c

Overview

Integer is the basis for the two concrete classes that

hold whole numbers, <code>Bignum</code> and <code>Fixnum</code>.

Direct Known Subclasses

Bignum, Fixnum

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Precision

included, #prec, #prec_f, #prec_i

Methods inherited from Numeric

#+@, #-@, #<=>, #abs, #coerce, #div, #divmod, #eql?, #initialize_copy, #modulo, #nonzero?, #quo, #remainder, #singleton_method_added, #step, #zero?

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?

Class Method Details

.induced_from(obj) ⇒ Fixnum

Convert obj to an Integer.

Returns:



1850
1851
1852
# File 'numeric.c', line 1850

static VALUE
rb_int_induced_from(klass, x)
VALUE klass, x;

Instance Method Details

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#chrString

Returns a string containing the ASCII character represented by the receiver’s value.

65.chr    #=> "A"
?a.chr    #=> "a"
230.chr   #=> "\346"

Returns:



1796
1797
1798
# File 'numeric.c', line 1796

static VALUE
int_chr(num)
VALUE num;

#downto(limit) {|i| ... } ⇒ Integer

Iterates block, passing decreasing values from int down to and including limit.

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

produces:

5.. 4.. 3.. 2.. 1..   Liftoff!

Yields:

  • (i)

Returns:



2687
2688
2689
# File 'numeric.c', line 2687

static VALUE
int_downto(from, to)
VALUE from, to;

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#integer?true

Always returns true.

Returns:

  • (true)


1755
1756
1757
# File 'numeric.c', line 1755

static VALUE
int_int_p(num)
VALUE num;

#nextInteger #succInteger

Returns the Integer equal to int + 1.

1.next      #=> 2
(-1).next   #=> 0

Overloads:



1773
1774
1775
# File 'numeric.c', line 1773

static VALUE
int_succ(num)
VALUE num;

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#nextInteger #succInteger

Returns the Integer equal to int + 1.

1.next      #=> 2
(-1).next   #=> 0

Overloads:



1773
1774
1775
# File 'numeric.c', line 1773

static VALUE
int_succ(num)
VALUE num;

#times {|i| ... } ⇒ Integer

Iterates block int times, passing in values from zero to int - 1.

5.times do |i|
  print i, " "
end

produces:

0 1 2 3 4

Yields:

  • (i)

Returns:



2727
2728
2729
# File 'numeric.c', line 2727

static VALUE
int_dotimes(num)
VALUE num;

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#to_iInteger #to_intInteger #floorInteger #ceilInteger #roundInteger #truncateInteger

As int is already an Integer, all these methods simply return the receiver.

Overloads:



1741
1742
1743
# File 'numeric.c', line 1741

static VALUE
int_to_i(num)
VALUE num;

#upto(limit) {|i| ... } ⇒ Integer

Iterates block, passing in integer values from int up to and including limit.

5.upto(10) { |i| print i, " " }

produces:

5 6 7 8 9 10

Yields:

  • (i)

Returns:



2648
2649
2650
# File 'numeric.c', line 2648

static VALUE
int_upto(from, to)
VALUE from, to;