class SubDiff::Diff
Stores a single match (and optional replacement) from a {String#sub} or {String#gsub} replacement.
It behaves just like a {String} and represents the newly replaced string if a replacement was made, or the matched string itself if no changes occurred.
It also has additional methods that provide access to the old string, the newly replaced string, and a boolean to determine if a replacement was actually made.
@api public
Attributes
value_was[R]
Public Class Methods
new(value, value_was = nil)
click to toggle source
Calls superclass method
# File lib/sub_diff/diff.rb 19 def initialize(value, value_was = nil) 20 @value_was = value_was || value 21 super(value) 22 end
Public Instance Methods
changed?()
click to toggle source
# File lib/sub_diff/diff.rb 24 def changed? 25 value != value_was 26 end
empty?()
click to toggle source
# File lib/sub_diff/diff.rb 28 def empty? 29 value.empty? && !changed? 30 end