Class: StringUtility
- Inherits:
-
Object
- Object
- StringUtility
- Defined in:
- lib/utils.rb
Instance Method Summary collapse
-
#initialize ⇒ StringUtility
constructor
Creates a new instance of the StringUtility class.
-
#separate_with(string, count = 3, separator = ',') ⇒ String
Separates the string by another string.
Constructor Details
#initialize ⇒ StringUtility
Creates a new instance of the StringUtility class
4 |
# File 'lib/utils.rb', line 4 def initialize; end |
Instance Method Details
#separate_with(string, count = 3, separator = ',') ⇒ String
Separates the string by another string. Useful for converting integers into human-readable numbers.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/utils.rb', line 11 def separate_with(string, count = 3, separator = ',') if separator.length > 1 separator = separator[0] end string = string.reverse! array = string.scan(/.{1,#{count}}/) string = array.join(separator) string = string.reverse! return string end |