Archive for November, 2010

Converting Classes in Ruby

November 10th, 2010 | Category: Basics

The two basic numeric data types in ruby floats and integers are treated in several classes or methods so we have to be very clear on which is which and how methods work on them. As discussed the standard mathematical operators treat numbers differently depending on the method they were presented a sample of which is shown below:

String#to_i : This method/operation converts String to Integer
String#to_f : This method/operation converts String to Float
Float#to_i : This method/operation converts Float to Integer
Float#to_s : This method/operation converts Float to String
Integer#to_f: This method/operation converts Integer to Float
Integer#to_s: This method/operation converts Integer to String

Comments are off for this post