Calculate the number of digits in an integer.
1.length #=> 1 10.length #=> 2 100.length #=> 3
CREDIT: Victor H. Goff III
Returns true if this integer is even, false otherwise.
2.even? #=> true 3.even? #=> false
CREDIT: Daniel Schierbeck
# File lib/core/facets/integer/odd.rb, line 31 def even? #self % 2 == 0 self & 1 == 0 end
Returns true if this integer is odd, false otherwise.
2.odd? #=> false 3.odd? #=> true -99.odd? # -> true -98.odd? # -> false
CREDIT: Daniel Schierbeck
# File lib/core/facets/integer/odd.rb, line 15 def odd? #self % 2 == 1 self & 1 == 1 end
# File lib/core/facets/integer/ordinal.rb, line 3 def ordinal if [11,12,13].include?(self % 100) "#{self}th" else case (self % 10) when 1 "#{self}st" when 2 "#{self}nd" when 3 "#{self}rd" else "#{self}th" end end end
See Float#round_at.
# File lib/core/facets/numeric/round.rb, line 27 def round_at(*args) to_f.round_at(*args) end
See Float#round_to.
# File lib/core/facets/numeric/round.rb, line 33 def round_to(*args) to_f.round_to(*args) end