D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Numeric
/
Filename :
coerce-i.ri
back
Copy
U:RDoc::AnyMethod[iI"coerce:ETI"Numeric#coerce;TF:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [I"@Returns a 2-element array containing two numeric elements, ;TI"6formed from the two operands +self+ and +other+, ;TI"!of a common compatible type.;To:RDoc::Markup::BlankLine o; ; [I"/Of the Core and Standard Library classes, ;TI"<Integer, Rational, and Complex use this implementation.;T@o; ; [I"Examples:;T@o:RDoc::Markup::Verbatim; [I"%i = 2 # => 2 ;TI"*i.coerce(3) # => [3, 2] ;TI".i.coerce(3.0) # => [3.0, 2.0] ;TI".i.coerce(Rational(1, 2)) # => [0.5, 2.0] ;TI"3i.coerce(Complex(3, 4)) # Raises RangeError. ;TI" ;TI")r = Rational(5, 2) # => (5/2) ;TI"2r.coerce(2) # => [(2/1), (5/2)] ;TI".r.coerce(2.0) # => [2.0, 2.5] ;TI"2r.coerce(Rational(2, 3)) # => [(2/3), (5/2)] ;TI"8r.coerce(Complex(3, 4)) # => [(3+4i), ((5/2)+0i)] ;TI" ;TI"*c = Complex(2, 3) # => (2+3i) ;TI"4c.coerce(2) # => [(2+0i), (2+3i)] ;TI"6c.coerce(2.0) # => [(2.0+0i), (2+3i)] ;TI"8c.coerce(Rational(1, 2)) # => [((1/2)+0i), (2+3i)] ;TI"4c.coerce(Complex(3, 4)) # => [(3+4i), (2+3i)] ;T:@format0o; ; [I"6Raises an exception if any type conversion fails.;T: @fileI"numeric.c;T:0@omit_headings_from_table_of_contents_below0I"coerce(other) -> array ;T0[ I" (p1);T@.FI"Numeric;TcRDoc::NormalClass00