Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/cotcube-helpers/numeric_ext.rb

Instance Method Summary collapse

Instance Method Details

#with_delimiter(deli = nil) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
# File 'lib/cotcube-helpers/numeric_ext.rb', line 2

def with_delimiter(deli=nil)
  raise ArgumentError, "Param delimiter can't be nil" if deli.nil?
  pre, post = self.to_s.split('.')
  pre = pre.chars.to_a.reverse.each_slice(3).map(&:join).join(deli).reverse
  post.nil? ? pre : [pre,post].join('.')
end