lib/garcon/core_ext/string.rb
# Breaks a string up into an array based on a regular expression.
# Similar to scan, but includes the matches.
#
# @example
#   s = "<p>This<b>is</b>a test.</p>"
#   s.shatter(/\<.*?\>/)
#     => [
#       [0] "<p>",
#       [1] "This",
#       [2] "<b>",
#       [3] "is",
#       [4] "</b>",
#       [5] "a test.",
#       [6] "</p>"
#     ]
#
# @param [Regexp] regex
#   Regular expression for breaking string into array.
#
# @return [String]
#
# @api public
Breaks a string up into an array based on a regular expression.
Similar to scan, but includes the matches.
Breaks a string up into an array based on a regular expression . Similar to scan but includes the matches .
def shatter(re)
    r = self.gsub(re) { |s| "\1" + s + "\1" }
    while r[ 0, 1] == "\1";  r[0] = ''; end
    while r[-1, 1] == "\1"; r[-1] = ''; end
    r.split("\1")
  end
def shatter ( re ) r = self . gsub ( re ) { | s | "\1" + s + "\1" } while r [ 0 , 1 ] == "\1" ; r [ 0 ] = '' ; end while r [ - 1 , 1 ] == "\1" ; r [ - 1 ] = '' ; end r . split ( "\1" ) end
Breaks a string up into an array based on a regular expression.
Breaks a string up into an array based on a regular expression .
None
String
re
<not_specific>
<not_specific>
regex Regular expression for breaking string into array.
regex Regular expression for breaking string into array .
example
None
api
None