Module: Extras::String
Instance Method Summary collapse
-
#char_to_a(char: "\s", strip: true) ⇒ Object
———————————————————————— Note: This method has support for “char” escaping to prevent splits.
Instance Method Details
#char_to_a(char: "\s", strip: true) ⇒ Object
Note: This method has support for “char” escaping to prevent splits. Split a string into an array.
25 26 27 28 29 30 |
# File 'lib/extras/string.rb', line 25 def char_to_a(char: "\s", strip: true) escaped = char.regexp_escape split(/(?<!\\)#{escaped}/).map do |v| strip ? v.gsub(/\\#{escaped}/, char) : v end end |