diff options
author | Akinori MUSHA <knu@idaemons.org> | 2019-01-24 17:13:24 +0900 |
---|---|---|
committer | Austin Ziegler <austin@zieglers.ca> | 2019-01-26 00:40:04 -0500 |
commit | 01e0caeda9ae38b7868f35987844fd9f67aef005 (patch) | |
tree | 3c71bfc6beb9d139af5dfd15f120ea0e7fea8d1c /lib | |
parent | 8b325657b09ff2e382d626deed38beb02731f96a (diff) | |
download | diff-lcs-01e0caeda9ae38b7868f35987844fd9f67aef005.tar.gz |
Add #to_ary to Diff::LCS::Change and Diff::LCS::ContextChange
It would be quite handy if you could write as follows:
```ruby
Diff::LCS.sdiff(a, b).each do |action, (old_position, old_element), (new_position, new_element)|
case action
when '!'
# replace
when '-'
# delete
when '+'
# insert
end
end
```
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diff/lcs/change.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb index 9229069..8dae83b 100644 --- a/lib/diff/lcs/change.rb +++ b/lib/diff/lcs/change.rb @@ -41,6 +41,8 @@ class Diff::LCS::Change [ @action, @position, @element ] end + alias to_ary to_a + def self.from_a(arr) arr = arr.flatten(1) case arr.size @@ -132,6 +134,8 @@ class Diff::LCS::ContextChange < Diff::LCS::Change ] end + alias to_ary to_a + def inspect(*args) to_a.inspect end |