Numeric

From RubySpec

Jump to: navigation, search

According to ruby-doc, "Numeric is a built-in class on which Fixnum, Bignum, etc., are based. Here some methods are added so that all number types can be treated to some extent as Complex numbers."

Examples:

 irb(main):001:0> 23.kind_of? Numeric
 => true
 irb(main):002:0> 23.5.kind_of? Numeric
 => true
 irb(main):003:0> 23.5.round
 => 24
 irb(main):004:0> 23.step(30,2) {|i| puts i*i} 
 529
 625
 729
 841
 => 23
 irb(main):005:0> 23.45454545.truncate 
 => 23
 irb(main):008:0> require 'complex'
 => true
 irb(main):009:0> y = Complex.new(5,5)
 => Complex(5, 5)
 irb(main):010:0> y.kind_of? Numeric
 => true
 irb(main):011:0> y.real
 => 5
Personal tools