public Method

Kernel.Integer(p1)

Integer(arg)     integer

Converts arg to a Fixnum or Bignum. Numeric types are converted directly (with floating point numbers being truncated). If arg is a String, leading radix indicators (0, 0b, and 0x) are honored. Others are converted using to_int and to_i. This behavior is different from that of String#to_i.

Integer(123.999)    #=> 123
Integer("0x1a")     #=> 26
Integer(Time.new)   #=> 1049896590

Source Code

/*
*  call-seq:
*     Integer(arg)    => integer
*  
*  Converts <i>arg</i> to a <code>Fixnum</code> or <code>Bignum</code>.
*  Numeric types are converted directly (with floating point numbers
*  being truncated). If <i>arg</i> is a <code>String</code>, leading
*  radix indicators (<code>0</code>, <code>0b</code>, and
*  <code>0x</code>) are honored. Others are converted using
*  <code>to_int</code> and <code>to_i</code>. This behavior is
*  different from that of <code>String#to_i</code>.
*     
*     Integer(123.999)    #=> 123
*     Integer("0x1a")     #=> 26
*     Integer(Time.new)   #=> 1049896590
*/

static VALUE
rb_f_integer(obj, arg)
   VALUE obj, arg;
{
   return rb_Integer(arg);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.