Module: SublimeDSL::Tools::ValueEquality
- Included in:
- SublimeText::Command, SublimeText::Command::Argument, SublimeText::KeyMap::Context, SublimeText::KeyMap::Context::Condition, SublimeText::KeyMap::KeyBinding, SublimeText::Keyboard::KeyStroke
- Defined in:
- lib/sublime_dsl/tools/value_equality.rb
Overview
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.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Returns true if the class of
otheris the same or a subclass ofself.class, and #value_id are the same using “==”. -
#hash ⇒ Object
Returns #hash for #value_id.
-
#value_id ⇒ Object
Default value identity: array of instance variable values.
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Returns true if the class of other is the same or a subclass of self.class, and #value_id are the same using “==”.
16 17 18 |
# 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 |
#hash ⇒ Object
Returns #hash for #value_id.
24 25 26 |
# File 'lib/sublime_dsl/tools/value_equality.rb', line 24 def hash value_id.hash end |
#value_id ⇒ Object
Default value identity: array of instance variable values.
30 31 32 |
# File 'lib/sublime_dsl/tools/value_equality.rb', line 30 def value_id instance_variables.map { |v| instance_variable_get(v) } end |