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