Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/midwire_common/fixnum.rb
Instance Method Summary collapse
-
#commify ⇒ Object
Format a number with commas and a decimal point.
- #is_even? ⇒ Boolean
- #is_odd? ⇒ Boolean
Instance Method Details
#commify ⇒ Object
Format a number with commas and a decimal point
3 4 5 6 7 8 9 |
# File 'lib/midwire_common/fixnum.rb', line 3 def commify to_s =~ /([^\.]*)(\..*)?/ int, dec = $1.reverse, $2 ? $2 : "" while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3') end int.reverse + dec end |
#is_even? ⇒ Boolean
11 12 13 |
# File 'lib/midwire_common/fixnum.rb', line 11 def is_even? self % 2 == 0 end |
#is_odd? ⇒ Boolean
15 16 17 |
# File 'lib/midwire_common/fixnum.rb', line 15 def is_odd? !is_even? end |