Module: Corefines::String::Remove
- Defined in:
- lib/corefines/string.rb
Instance Method Summary collapse
-
#remove(*patterns) ⇒ String
Returns a copy of this string with all occurrences of the patterns removed.
-
#remove!(*patterns) ⇒ String
Removes all the occurrences of the patterns in place.
Instance Method Details
#remove(*patterns) ⇒ String
Returns a copy of this string with all occurrences of the patterns removed.
The pattern is typically a Regexp; if given as a String, any
regular expression metacharacters it contains will be interpreted
literally, e.g. '\\d' will match a backlash followed by 'd', instead
of a digit.
335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/corefines/string.rb', line 335 module Remove refine ::String do def remove(*patterns) dup.remove!(*patterns) end def remove!(*patterns) patterns.each { |pattern| gsub!(pattern, '') } self end end end |
#remove!(*patterns) ⇒ String
Removes all the occurrences of the patterns in place.
335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/corefines/string.rb', line 335 module Remove refine ::String do def remove(*patterns) dup.remove!(*patterns) end def remove!(*patterns) patterns.each { |pattern| gsub!(pattern, '') } self end end end |