module SublimeDSL::Tools::ValueEquality
A mix-in allowing to compare objects based on value rather than identity.
It redefines eql?
, hash
and #== based on a value_id
method, and provides a default implementation for value_id
.
Public Instance Methods
eql?(other)
click to toggle source
Returns true if the class of other
is the same or a subclass of self.class
, and value_id
are the same using “==”.
# File lib/sublime_dsl/tools/value_equality.rb, line 16 def eql?(other) other.is_a?(self.class) && other.value_id == self.value_id end
Also aliased as: ==
hash()
click to toggle source
value_id()
click to toggle source
Default value identity: array of instance variable values.
# File lib/sublime_dsl/tools/value_equality.rb, line 30 def value_id instance_variables.map { |v| instance_variable_get(v) } end