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
38 39 40 |
# File 'lib/utils.rb', line 38 def chars_only gsub(/[^0-9A-Za-z]/, '') end |
#csv_unquote ⇒ Object
30 31 32 |
# File 'lib/utils.rb', line 30 def csv_unquote unquote.unquote.unquote end |
#initial ⇒ Object
22 23 24 |
# File 'lib/utils.rb', line 22 def initial self[0, 1] end |
#number? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/utils.rb', line 16 def number? true if Integer(self) rescue StandardError false end |
#range_present? ⇒ Boolean
12 13 14 |
# File 'lib/utils.rb', line 12 def range_present? !empty? end |
#remove_trailing_number ⇒ Object
34 35 36 |
# File 'lib/utils.rb', line 34 def remove_trailing_number gsub(/([^\d]*)\d+$/, '\1') end |
#unquote ⇒ Object
26 27 28 |
# File 'lib/utils.rb', line 26 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 |