Sha256: e0e8492fab4c6226c82c4132e87989a942f1e6024e4b92a0c2716e328d21afa7

Contents?: true

Size: 496 Bytes

Versions: 7

Compression:

Stored size: 496 Bytes

Contents

class String

  # Breaks a string up into an array based on a regular expression.
  # Similar to scan, but includes the matches.
  #
  #   s = "<p>This<b>is</b>a test.</p>"
  #   s.shatter( /\<.*?\>/ )
  #
  # _produces_
  #
  #   ["<p>", "This", "<b>", "is", "</b>", "a test.", "</p>"]
  #
  #   CREDIT: Trans

  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

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/string/shatter.rb
facets-2.4.1 lib/facets/string/shatter.rb
facets-2.4.2 lib/core/facets/string/shatter.rb
facets-2.4.3 lib/core/facets/string/shatter.rb
facets-2.4.4 lib/core/facets/string/shatter.rb
facets-2.4.5 lib/core/facets/string/shatter.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/shatter.rb