D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Kernel
/
Filename :
Integer-i.ri
back
Copy
U:RDoc::AnyMethod[iI"Integer:ETI"Kernel#Integer;TF:publico:RDoc::Markup::Document:@parts[1o:RDoc::Markup::Paragraph; [I"0Returns an integer converted from +object+.;To:RDoc::Markup::BlankLine o; ; [I"-Tries to convert +object+ to an integer ;TI"-using +to_int+ first and +to_i+ second; ;TI"see below for exceptions.;T@o; ; [I"FWith a non-zero +base+, +object+ must be a string or convertible ;TI"to a string.;T@S:RDoc::Markup::Heading: leveli : textI"\Numeric objects;T@o; ; [I"?With an integer argument +object+ given, returns +object+:;T@o:RDoc::Markup::Verbatim; [I"&Integer(1) # => 1 ;TI"'Integer(-1) # => -1 ;T:@format0o; ; [I"4With a floating-point argument +object+ given, ;TI".returns +object+ truncated to an integer:;T@o;; [I"=Integer(1.9) # => 1 # Rounds toward zero. ;TI"=Integer(-1.9) # => -1 # Rounds toward zero. ;T;0S;; i ;I"\String objects;T@o; ; [I"<With a string argument +object+ and zero +base+ given, ;TI"9returns +object+ converted to an integer in base 10:;T@o;; [I" Integer('100') # => 100 ;TI"!Integer('-100') # => -100 ;T;0o; ; [I"FWith +base+ zero, string +object+ may contain leading characters ;TI"2to specify the actual base (radix indicator):;T@o;; [I"?Integer('0100') # => 64 # Leading '0' specifies base 8. ;TI"@Integer('0b100') # => 4 # Leading '0b' specifies base 2. ;TI"AInteger('0x100') # => 256 # Leading '0x' specifies base 16. ;T;0o; ; [I"EWith a positive +base+ (in range 2..36) given, returns +object+ ;TI"/converted to an integer in the given base:;T@o;; [I" Integer('100', 2) # => 4 ;TI"!Integer('100', 8) # => 64 ;TI"#Integer('-100', 16) # => -256 ;T;0o; ; [I"GWith a negative +base+ (in range -36..-2) given, returns +object+ ;TI"6converted to the radix indicator if it exists or ;TI"+base+:;T@o;; [I"%Integer('0x100', -2) # => 256 ;TI"#Integer('100', -2) # => 4 ;TI"#Integer('0b100', -8) # => 4 ;TI"$Integer('100', -8) # => 64 ;TI"$Integer('0o100', -10) # => 64 ;TI"%Integer('100', -10) # => 100 ;T;0o; ; [I"-+base+ -1 is equivalent to the -10 case.;T@o; ; [I"NWhen converting strings, surrounding whitespace and embedded underscores ;TI"are allowed and ignored:;T@o;; [I"$Integer(' 100 ') # => 100 ;TI"%Integer('-1_0_0', 16) # => -256 ;T;0S;; i ;I"Other classes;T@o; ; [I"5Examples with +object+ of various other classes:;T@o;; [I"<Integer(Rational(9, 10)) # => 0 # Rounds toward zero. ;TI"EInteger(Complex(2, 0)) # => 2 # Imaginary part must be zero. ;TI".Integer(Time.now) # => 1650974042 ;T;0S;; i ;I" Keywords;T@o; ; [I"RWith the optional keyword argument +exception+ given as +true+ (the default):;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"IRaises TypeError if +object+ does not respond to +to_int+ or +to_i+.;To;;0; [o; ; [I"+Raises TypeError if +object+ is +nil+.;To;;0; [o; ; [I";Raises ArgumentError if +object+ is an invalid string.;T@o; ; [I"OWith +exception+ given as +false+, an exception of any kind is suppressed ;TI"and +nil+ is returned.;T: @fileI"kernel.rb;T:0@omit_headings_from_table_of_contents_below0I"BInteger(object, base = 0, exception: true) -> integer or nil ;T0[ I"%(arg, base = 0, exception: true);T@|FI"Kernel;TcRDoc::NormalModule00