CHAPTER 6

image

Numbers

The Numeric class within Ruby is a containing class for the Integer and Float classes. This contains all methods linked to numeric variables either with (float) or without (integer) decimal places. The Numeric class is a very simple class, which holds the ability to perform a number of complex calculations with numbers.

Creating Numbers

Creating a number in Ruby is extremely simple, rather like creating a String. Rather than using a New method, or a set of braces, like an array or hash, a Number is created by setting a variable without quotation marks. If the number contains a decimal place, it is created as a float; if the number ...

Get Ruby Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.