Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bones.rb,
lib/common.rb
Overview
Extending the Ruby standard string class to support some additional methods. This includes a hack of the gsub! command.
Instance Method Summary collapse
-
#remove_double_commas ⇒ Object
Replace double comma’s in a string with a single comma.
-
#remove_extra_commas ⇒ Object
Remove a comma before a closing bracket in a string, for example: ‘,)’.
-
#remove_extras ⇒ Object
This function repeatedly applies the remove double commas and remove extra commas functions.
Instance Method Details
#remove_double_commas ⇒ Object
Replace double comma’s in a string with a single comma. This method is useful for function-argument lists.
20 21 22 |
# File 'lib/bones.rb', line 20 def remove_double_commas return self.gsub!(/(,\s*){2,}/,',') end |
#remove_extra_commas ⇒ Object
Remove a comma before a closing bracket in a string, for example: ‘,)’. This method is useful for function-argument lists.
27 28 29 |
# File 'lib/bones.rb', line 27 def remove_extra_commas return self.gsub!(/,\s*\)/,')') end |
#remove_extras ⇒ Object
This function repeatedly applies the remove double commas and remove extra commas functions
33 34 35 |
# File 'lib/bones.rb', line 33 def remove_extras return self.remove_double_commas.remove_extra_commas.remove_double_commas.remove_extra_commas end |