Module: Capistrano::DataPlaneApi::Equatable

Included in:
Type
Defined in:
lib/capistrano/data_plane_api/equatable.rb

Overview

Include in a class to make its instances capable of comparing themselves with other objects of the same class by calling ‘==` on their instance variables.

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Parameters:

  • other (Object)

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capistrano/data_plane_api/equatable.rb', line 11

def eql?(other)
  return true if equal?(other)
  return false unless other.is_a?(self.class) || is_a?(other.class)

  # @type [Set<Symbol>]
  self_ivars = instance_variables.to_set
  # @type [Set<Symbol>]
  other_ivars = other.instance_variables.to_set

  return false unless self_ivars == other_ivars

  self_ivars.each do |ivar|
    return false if instance_variable_get(ivar) != other.instance_variable_get(ivar)
  end

  true
end