- 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_ion a String
- Truth
- 0 is truthy
- Order of Operations
- Core Ruby
- Core Math Operators (
+,-,*,/) - Modulo
% timesto_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/2vs1/2)
- Core Ruby
- Core Math Operators (
+,-,*,/) ceilto_i/floorto_s
- Core Math Operators (
Maybe also:
num1 *num2is different fromnum1 * num2)