Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utils.rb
Overview
monkey-patch String class
Instance Method Summary collapse
- #chars_only ⇒ Object
- #csv_unquote ⇒ Object
- #initial ⇒ Object
- #number? ⇒ Boolean
- #range_present? ⇒ Boolean
- #remove_trailing_number ⇒ Object
- #unquote ⇒ Object
- #unwrap ⇒ Object
Instance Method Details
#chars_only ⇒ Object
36 37 38 |
# File 'lib/utils.rb', line 36 def chars_only gsub(/[^0-9A-Za-z]/, '') end |
#csv_unquote ⇒ Object
28 29 30 |
# File 'lib/utils.rb', line 28 def csv_unquote unquote.unquote.unquote end |
#initial ⇒ Object
20 21 22 |
# File 'lib/utils.rb', line 20 def initial self[0, 1] end |
#number? ⇒ Boolean
16 17 18 |
# File 'lib/utils.rb', line 16 def number? !!Integer(self, exception: false) end |
#range_present? ⇒ Boolean
12 13 14 |
# File 'lib/utils.rb', line 12 def range_present? !empty? end |
#remove_trailing_number ⇒ Object
32 33 34 |
# File 'lib/utils.rb', line 32 def remove_trailing_number gsub(/([^\d]*)\d+$/, '\1') end |
#unquote ⇒ Object
24 25 26 |
# File 'lib/utils.rb', line 24 def unquote delete_suffix('"').delete_prefix('"').delete_suffix('\'').delete_prefix('\'') end |
#unwrap ⇒ Object
5 6 7 8 9 10 |
# File 'lib/utils.rb', line 5 def unwrap s = self s = s[1..s.length - 1] if s.start_with?('(') s = s[0..s.length - 2] if s.end_with?(')') s end |