- Numbers in Ruby are Objects
- We can call methods on numbers
- We can define methods on numbers
- Tricks with Numbers
- Integer with Integer gives Integer
- Integer with Float gives Float
- Calling
to_i
on a String
- Truth
- 0 is truthy
- Order of Operations
- Core Ruby
- Core Math Operators (
+
,-
,*
,/
) - Modulo
%
times
to_s
/to_f
- Core Math Operators (
- With
ActiveSupport
- Date/Time Extensions:
.hours
,.days
,.weeks
,.months
,.years
,.ago
/.until
,.since
/.from_now
- Byte Extensions:
.bytes
,.kilobytes
,.megabytes
,.gigabytes
ordinalize
- Date/Time Extensions:
- Challenges when using Floats
- Math is not precise
- Formatting can be more difficult
- Alternatives
BigDecimal
- Avoiding fractional components
- Using
Kernel.format
- Whole Number Math vs. Fractional Math (ex:
1.0/2
vs1/2
)
- Core Ruby
- Core Math Operators (
+
,-
,*
,/
) ceil
to_i
/floor
to_s
- Core Math Operators (
Maybe also:
num1 *num2
is different fromnum1 * num2
)