Class: String
Overview
Overloads the String class.
@author: Tasos “Zapotek” Laskos
<[email protected]>
<[email protected]>
@version: 0.1
Instance Method Summary collapse
-
#rdiff(str) ⇒ String
Gets the reverse diff between self and str on a word level.
- #substring?(string) ⇒ Boolean
Instance Method Details
#rdiff(str) ⇒ String
Gets the reverse diff between self and str on a word level.
self = <<END
This is the first test.
Not really sure what else to put here...
END
str = <<END
This is the second test.
Not really sure what else to put here...
Boo-Yah!
END
self.rdiff( str )
# => "This is the test.\nNot really sure what else to put here...\n"
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/arachni/ruby/string.rb', line 44 def rdiff( str ) return self if self == str # get the words of the first text in an array words1 = self.split( /\b/ ) # get the words of the second text in an array words2 = str.split( /\b/ ) # get all the words that are different between the 2 arrays # math style! changes = words1 - words2 changes << words2 - words1 changes.flatten! # get what hasn't changed (the rdiff, so to speak) as a string return ( words1 - changes ).join( '' ) end |
#substring?(string) ⇒ Boolean
65 66 67 68 69 70 71 72 |
# File 'lib/arachni/ruby/string.rb', line 65 def substring?( string ) begin match = match( Regexp.new( Regexp.escape( string ) ) ) match && !match.to_s.empty? rescue return nil end end |