Iterates the given block, passing in integer values from int up to and including limit.
If no block is given, an Enumerator is returned instead.
5.upto(10) {|i| print i, " " } #=> 5 6 7 8 9 10
Iterates the given block, passing in decreasing values from int down to and including limit.
If no block is given, an Enumerator is returned instead.
5.downto(1) { |n| print n, ".. " } puts "Liftoff!" #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
Returns the predecessor of int, i.e. the Integer equal to int-1.
1.pred #=> 0 (-1).pred #=> -2
Returns the int itself.
97.ord #=> 97
This method is intended for compatibility to character literals in Ruby 1.9.
For example, ?a.ord returns 97 both in 1.8 and 1.9.
Returns the largest number less than or equal to int with a precision of ndigits decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros.
Returns self when ndigits is zero or positive.
1.floor #=> 1 1.floor(2) #=> 1 18.floor(-1) #=> 10 (-18).floor(-1) #=> -20
Returns the remainder after dividing int by numeric.
x.remainder(y) means x-y*(x/y).truncate.
5.remainder(3) #=> 2 -5.remainder(3) #=> -2 5.remainder(-3) #=> 2 -5.remainder(-3) #=> -2 5.remainder(1.5) #=> 0.5
See Numeric#divmod.
Returns the value as a rational.
1.to_r #=> (1/1) (1<<64).to_r #=> (18446744073709551616/1)
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns false, even if the complex number has no imaginary part.
Returns the value as a string.
Complex(2).to_s #=> "2+0i" Complex('-8/6').to_s #=> "-4/3+0i" Complex('1/2i').to_s #=> "0+1/2i" Complex(0, Float::INFINITY).to_s #=> "0+Infinity*i" Complex(Float::NAN, Float::NAN).to_s #=> "NaN+NaN*i"
Returns the value as an integer if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_i #=> 1 Complex(1, 0.0).to_i # RangeError Complex(1, 2).to_i # RangeError
Returns the value as a float if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_f #=> 1.0 Complex(1, 0.0).to_f # RangeError Complex(1, 2).to_f # RangeError
Returns the value as a rational if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_r #=> (1/1) Complex(1, 0.0).to_r # RangeError Complex(1, 2).to_r # RangeError
See rationalize.
Returns zero as a complex.
Returns nil represented as a BigDecimal.
require 'bigdecimal' require 'bigdecimal/util' nil.to_d # => 0.0
Always returns the empty string.