Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created August 16, 2008 09:29
Show Gist options
  • Save ELLIOTTCABLE/5705 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/5705 to your computer and use it in GitHub Desktop.
Array#to_i - turn a comma-delimited number into an integer
class Array
def to_i
i = 0
numeral = 0
self.reverse.inject(0) do |int, section|
i += 1
int += section * (10 ** numeral)
numeral += section.to_i.to_s.size
int
end
end
end
[11,694,331.42].to_i #=> 11694331.42
[999,999,999,999,999].to_i #=> 999999999999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment