Skip to content

Instantly share code, notes, and snippets.

@midwire
Created August 19, 2014 01:17
Show Gist options
  • Select an option

  • Save midwire/188dc225f6616f076184 to your computer and use it in GitHub Desktop.

Select an option

Save midwire/188dc225f6616f076184 to your computer and use it in GitHub Desktop.
Enhanced Ruby Fixnum class
class Fixnum
# Format a number with commas and a decimal point
def commify
to_s =~ /([^\.]*)(\..*)?/
int, dec = $1.reverse, $2 ? $2 : ""
while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3')
end
int.reverse + dec
end
def is_even?
self % 2 == 0
end
def is_odd?
!is_even?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment