Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/cotcube-helpers/string_ext.rb,
lib/cotcube-helpers/swig/date.rb
Overview
Monkey patching the Ruby Core class String
Instance Method Summary collapse
- #escape_regex ⇒ Object
- #to_date ⇒ Object
- #to_time ⇒ Object
-
#valid_json? ⇒ Boolean
(also: #is_valid_json?)
…
Instance Method Details
#escape_regex ⇒ Object
13 14 15 |
# File 'lib/cotcube-helpers/string_ext.rb', line 13 def escape_regex chars.map{|z| %w[ . | ( ) [ ] { } \ ^ $ + * ? ].include?(z) ? "\\#{z}" : z }.join end |
#to_date ⇒ Object
28 29 30 |
# File 'lib/cotcube-helpers/swig/date.rb', line 28 def to_date Date::strptime(self, "%Y-%m-%d") end |
#to_time ⇒ Object
32 33 34 |
# File 'lib/cotcube-helpers/swig/date.rb', line 32 def to_time DateTime::strptime(self, "%s") end |
#valid_json? ⇒ Boolean Also known as: is_valid_json?
…
6 7 8 9 10 11 |
# File 'lib/cotcube-helpers/string_ext.rb', line 6 def valid_json? JSON.parse(self) true rescue JSON::ParserError false end |