class SubDiff::Collection
Stores a collection of {Diff} objects for all matches from a {String#sub_diff} or {String#gsub_diff} replacement.
It behaves like a {String} that represents the entire replacement result from {String#sub} or {String#gsub}.
It also behaves like an {Enumerable} by delegating to {Collection#diffs} - an {Array} containing each {Diff}.
@api public
Attributes
diffs[R]
string[R]
Public Class Methods
new(string)
click to toggle source
Calls superclass method
# File lib/sub_diff/collection.rb 20 def initialize(string) 21 @string = string 22 @diffs = [] 23 super(string) 24 end
Public Instance Methods
changed?()
click to toggle source
# File lib/sub_diff/collection.rb 26 def changed? 27 diffs.any?(&:changed?) 28 end
clear()
click to toggle source
# File lib/sub_diff/collection.rb 30 def clear 31 diffs.clear 32 __setobj__('') 33 self 34 end
push(diff)
click to toggle source
# File lib/sub_diff/collection.rb 36 def push(diff) 37 unless diff.empty? 38 diffs << diff 39 __setobj__(diffs.join) 40 end 41 end
reset() { || ... }
click to toggle source
# File lib/sub_diff/collection.rb 43 def reset 44 clear 45 __setobj__(string) 46 yield if block_given? 47 self 48 end