Rubyには差分を求めるライブラリが存在する
require 'diff/lcs'
Diff::LCS.diff(A, B)
: 配列の要素に差があれば差分をとる
Diff::LCS.diff([2, 3, 4, 'b'], [1, 2, 3, 'a', 'b'])
#=> [[["+", 0, 1]], [["-", 2, 4], ["+", 3, "a"]]]
Diff::LCS.sdiff(A, B)
: 配列の要素1つごとに差分があるかを返す
Diff::LCS.sdiff([2, 3, 4, 'b'], [1, 2, 3, 'a', 'b'])
#=> [["+", [0, nil], [0, 1]], ["=", [0, 2], [1, 2]], ["=", [1, 3], [2, 3]], ["!", [2, 4], [3, "a"]], ["=", [3, "b"], [4, "b"]]]
Diff::LCS::Change
オブジェクトに使えるメソッド
:<=>
, :==
, :inspect
, :to_a
, :new_element
, :old_position
, :new_position
, :old_element
, :changed?
, :action
, :adding?
, :deleting?
, :unchanged?
, :finished_a?
, :finished_b?
, :<
, :>
, :<=
, :>=
, :between?
, :tap
, :public_send
, :instance_variables
, :instance_variable_set
, :instance_variable_defined?
, :remove_instance_variable
, :private_methods
, :kind_of?
, :is_a?
, :instance_variable_get
, :instance_of?
, :public_method
, :extend
, :define_singleton_method
, :singleton_method
, :to_enum
, :enum_for
, :===
, :=~
, :!~
, :eql?
, :respond_to?
, :freeze
, :display
, :object_id
, :send
, :to_s
, :method
, :nil?
, :hash
, :class
, :singleton_class
, :clone
, :dup
, :itself
, :taint
, :tainted?
, :untaint
, :untrust
, :trust
, :untrusted?
, :methods
, :protected_methods
, :frozen?
, :public_methods
, :singleton_methods
, :!
, :!=
, :__send__
, :equal?
, :instance_eval
, :instance_exec
, :__id__