Class: RubyJS.Integer

Defined in: lib/corelib/integer.coffee
Inherits: RubyJS.Numeric

Overview

Integer is a module for Integer number formats. The actual implementation is Fixnum.

Direct Known Subclasses

RubyJS.Fixnum

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from RubyJS.Numeric

.isNumeric, .try_convert, .new, .typecast, '-instance'>#'<=>', #abs, #abs2, #ceil, #coerce, #div, #divmod, #eql, #inspect, #fdiv, #floor, #magnitude, #modulo, #nonzero, #quo, #rect, #remainder, #round, #step, #truncate, #uminus, #zero

Methods inherited from RubyJS.Object

.include, .__add_default_aliases__, #send, #respond_to, #to_enum, #tap

Class Method Details

+ (void) new(value)

+ (void) isInteger(obj)

Instance Method Details

- (R.String) chr()

Returns a string containing the character represented by the receiver’s value according to encoding.

Examples:


  R(65).chr()                   #=> "A"
  R(230).chr()                  #=> "\346"
  R(255).chr(Encoding::UTF_8)   #=> "\303\277"

Returns:

  • R.String

- (R.Fixnum) denominator()

Returns 1.

Returns:

  • R.Fixnum

- (this) downto(stop, block)

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

If no block is given, an enumerator is returned instead.

Examples:


 R(5).downto(1, function (n) { R.puts(n + ".. ") }
 # => 5.. 4.. 3.. 2.. 1..

Parameters:

  • stop (Number)

Returns:

  • this

- (Boolean) even()

Returns true if int is an even number.

Returns:

  • Boolean

- (R.Fixnum) gcd(other)

Returns the greatest common divisor (always positive). 0.gcd(x) and x.gcd(0) return abs(x).

Examples:


  R(2).gcd(2)                    #=> 2
  R(3).gcd(-7)                   #=> 1
  R((1<<31)-1).gcd((1<<61)-1)    #=> 1

Returns:

  • R.Fixnum

- (R.Array<R.Fixnum, R.Fixnum>) gcdlcm(other)

Returns an array; [int.gcd(int2), int.lcm(int2)].

Examples:


  R(2).gcdlcm(2)                    #=> [2, 2]
  R(3).gcdlcm(-7)                   #=> [1, 21]
  R((1<<31)-1).gcdlcm((1<<61)-1)    #=> [1, 4951760154835678088235319297]

Returns:

  • R.Array<R.Fixnum, R.Fixnum>

- (R.Fixnum) lcm(other)

Returns the least common multiple (always positive). 0.lcm(x) and x.lcm(0) return zero.

Examples:


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

Returns:

  • R.Fixnum

- (R.Fixnum,this) numerator()

Returns self.

Returns:

  • R.Fixnum, this

- (Boolean) odd()

Returns true if int is an odd number.

Returns:

  • Boolean

- (this) ord()

Returns the int itself.

 a.ord    #=> 97

This method is intended for compatibility to character constant in Ruby 1.9. For example, ?a.ord returns 97 both in 1.8 and 1.9.

Returns:

  • this

- (R.Fixnum) next()

Returns the Integer equal to int + 1.

@alias #succ

Examples:


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

Returns:

  • R.Fixnum

- (R.Fixnum) pred()

Returns the Integer equal to int - 1.

Examples:


  R(1).pred()    #=> 0
  R(-1).pred()   #=> -2

Returns:

  • R.Fixnum

- (R.Fixnum) round(n)

Rounds to a given precision in decimal digits (default 0 digits). Precision may be negative. Returns a floating point number when ndigits is positive, self for zero, and round down for negative.

Examples:


  R(1).round()      #=> 1
  R(1).round(2)     #=> 1.0
  R(15).round(-1)   #=> 20

Returns:

  • R.Fixnum

- (this) times(block)

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

If no block is given, an enumerator is returned instead.

Examples:


  R(5).times(function(i) { R.puts(i) })
  # => 0 1 2 3 4

Returns:

  • this

- (this) to_i()

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

Returns:

  • this

- (this) upto(stop, block)

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

If no block is given, an enumerator is returned instead.

Examples:


  R(5).upto(10, function (i) { R.puts(i + " " })
  # => 5 6 7 8 9 10

Parameters:

  • stop (Number)

Returns:

  • this

- (String) toString()

Returns:

  • String