Class: String

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

Overview

Extends String class with to_comma and updated to_i

Instance Method Summary collapse

Instance Method Details

#add_commasObject



32
33
34
# File 'lib/number_name_string.rb', line 32

def add_commas
  self.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
end

#old_to_iObject



26
# File 'lib/number_name_string.rb', line 26

alias_method :old_to_i, :to_i

#to_commaObject



28
29
30
# File 'lib/number_name_string.rb', line 28

def to_comma
  self.to_i.to_comma
end

#to_iObject



36
37
38
39
40
41
42
# File 'lib/number_name_string.rb', line 36

def to_i
  if self =~ /^\d+$/
    old_to_i
  else
    NumberNameString[self]
  end
end