Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/midwire_common/fixnum.rb

Instance Method Summary collapse

Instance Method Details

#commifyObject

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

Returns:

  • (Boolean)


11
12
13
# File 'lib/midwire_common/fixnum.rb', line 11

def is_even?
  self % 2 == 0
end

#is_odd?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/midwire_common/fixnum.rb', line 15

def is_odd?
  !is_even?
end