Class: SubDiff::Diff
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SubDiff::Diff
- Defined in:
- lib/sub_diff/diff.rb
Overview
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.
Instance Attribute Summary collapse
- #value_was ⇒ Object readonly
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(value, value_was = nil) ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize(value, value_was = nil) ⇒ Diff
Returns a new instance of Diff.
19 20 21 22 |
# File 'lib/sub_diff/diff.rb', line 19 def initialize(value, value_was = nil) @value_was = value_was || value super(value) end |
Instance Attribute Details
#value_was ⇒ Object (readonly)
15 16 17 |
# File 'lib/sub_diff/diff.rb', line 15 def value_was @value_was end |
Instance Method Details
#changed? ⇒ Boolean
24 25 26 |
# File 'lib/sub_diff/diff.rb', line 24 def changed? value != value_was end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/sub_diff/diff.rb', line 28 def empty? value.empty? && !changed? end |