Class: String
Instance Method Summary collapse
- #remove(string_or_rx) ⇒ Object
- #remove!(string_or_rx) ⇒ Object
- #remove_all(string_or_rx) ⇒ Object
- #remove_all!(string_or_rx) ⇒ Object
-
#safe_constantize ⇒ Object
Return the constant that this string refers to, or nil if ActiveSupport cannot load such a constant.
Instance Method Details
#remove(string_or_rx) ⇒ Object
3 4 5 |
# File 'lib/hobo_support/string.rb', line 3 def remove(string_or_rx) sub(string_or_rx, '') end |
#remove!(string_or_rx) ⇒ Object
7 8 9 |
# File 'lib/hobo_support/string.rb', line 7 def remove!(string_or_rx) sub!(string_or_rx, '') end |
#remove_all(string_or_rx) ⇒ Object
11 12 13 |
# File 'lib/hobo_support/string.rb', line 11 def remove_all(string_or_rx) gsub(string_or_rx, '') end |
#remove_all!(string_or_rx) ⇒ Object
15 16 17 |
# File 'lib/hobo_support/string.rb', line 15 def remove_all!(string_or_rx) gsub!(string_or_rx, '') end |
#safe_constantize ⇒ Object
Return the constant that this string refers to, or nil if ActiveSupport cannot load such a constant. This is much safer than ‘rescue NameError`, as that will mask genuine NameErrors that have been made in the code being loaded (#safe_constantize will not)
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hobo_support/string.rb', line 22 def safe_constantize Object.class_eval self rescue NameError => e if e.missing_name != self # oops - some other name error raise else nil end end |