differ icon indicating copy to clipboard operation
differ copied to clipboard

Please remove protected from raw_array

Open SamiSieranoja opened this issue 5 years ago • 3 comments

Hi.

Could you remove "protected" from raw_array? I need the diff output in machine readable format (rather than display to user), and raw_array seems the most usable format. My use case is that I'm developing a text editor (https://github.com/SamiSieranoja/vimamsa) and I want to process the buffer contents with external program and then include the diffs of before/after in undo history.

diff --git a/lib/differ/diff.rb b/lib/differ/diff.rb
index 76d3012..5f46cb6 100644
--- a/lib/differ/diff.rb
+++ b/lib/differ/diff.rb
@@ -82,7 +82,7 @@ module Differ
       end
     end
 
-  protected
+#  protected
     def raw_array
       @raw
     end

SamiSieranoja avatar Mar 02 '19 22:03 SamiSieranoja

You can create a subclass and expose #raw_array there, or just do diff.send :raw_array.

mvz avatar Jan 22 '20 10:01 mvz

That's unnecessarily cumbersome. Please do do something here, perhaps provide #to_a ?

sixtyfive avatar Sep 28 '21 16:09 sixtyfive

I agree, I'm in the same situation. I want to process only the changes, not the part of the text that stays the same, and the only way to do so seems to be for me to go through the raw_array myself. While it is true that I can work around this by doing diff.send(:raw_array), having a properly exposed API would be a lot cleaner, perhaps called #to_a as suggested earlier or simply #parts. Thanks for a great little gem otherwise!

lenlo avatar Nov 19 '22 20:11 lenlo