Module: SiteHub::Equality

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



12
13
14
# File 'lib/sitehub/equality.rb', line 12

def self.included(clazz)
  clazz.extend(ClassMethods)
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/sitehub/equality.rb', line 16

def ==(other)
  return false unless other.is_a?(_clazz)
  fields = instance_variables.find_all { |field| !_clazz.transient_fields.include?(field) }
  fields.all? do |variable|
    instance_variable_get(variable) == other.instance_variable_get(variable)
  end
end

#_clazzObject



24
25
26
# File 'lib/sitehub/equality.rb', line 24

def _clazz
  self.class
end