Sha256: bcc7c4858c33ec504dc5213f8abf4d4cda1379ffca97bc987aad19b4c9197d1f

Contents?: true

Size: 494 Bytes

Versions: 20

Compression:

Stored size: 494 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

20 entries across 19 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/shatter.rb
facets-3.1.0 lib/core/facets/string/shatter.rb
facets-3.0.0 lib/core/facets/string/shatter.rb
facets-2.9.3 lib/core/facets/string/shatter.rb
facets-2.9.2 lib/core/facets/string/shatter.rb
facets-2.9.2 src/core/facets/string/shatter.rb
facets-2.9.1 lib/core/facets/string/shatter.rb
facets-2.9.0 lib/core/facets/string/shatter.rb
facets-2.9.0.pre.2 lib/core/facets/string/shatter.rb
facets-2.9.0.pre.1 lib/core/facets/string/shatter.rb
facets-2.8.4 lib/core/facets/string/shatter.rb
facets-2.8.3 lib/core/facets/string/shatter.rb
facets-2.8.2 lib/core/facets/string/shatter.rb
facets-2.8.1 lib/core/facets/string/shatter.rb
facets-2.8.0 lib/core/facets/string/shatter.rb
facets-2.7.0 lib/core/facets/string/shatter.rb
facets-2.6.0 lib/core/facets/string/shatter.rb
facets-2.5.0 lib/core/facets/string/shatter.rb
facets-2.5.1 lib/core/facets/string/shatter.rb
facets-2.5.2 lib/core/facets/string/shatter.rb