Numbers

 
   

Ruby Way
By Hal Fulton
Slots : 1.0
Table of Contents
 


Ruby automatically detects and converts between small and large integersthere is no need to use a trailing L at any time. There is no j literal for imaginary numbers. Use the Complex class from complex.rb to work with complex numbers. Use to_i and to_f to convert values.

Number objects are instances of a class like the others, and you can define methods for them.

 

 class Fixnum  def winner?  self == 37  end end puts "Pick a number." if gets.to_i.winner?  puts "Right!" else  puts "Sorry." end 

This is an example of extending a built-in class with Ruby.


   

 

 



The Ruby Way
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2000
Pages: 119
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net