Rational

Rational(x[, y]) â numeric
Instance Public methods

Returns x/y;

Rational(1, 2)   #=> (1/2)
Rational('1/2')  #=> (1/2)
Rational(nil)    #=> TypeError
Rational(1, nil) #=> TypeError

Syntax of string form:

string form = extra spaces , rational , extra spaces ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;

See String#to_r.

doc_ruby_on_rails
2015-04-17 08:31:00
Comments
Leave a Comment

Please login to continue.