Module: InstanceEquality

Included in:
ComponentDescriptors::ComponentDefinition, ComponentDescriptors::Field
Defined in:
lib/instance_equality.rb

Overview

This module provides a class method macro for defining ==, eql? and hashcode methods based on a specified set of instance variables.

class Foo

attr_accessors :bar, :baz
extend InstanceEquality
equality_and_hashcode_from :bar, :baz

...

end

a,b = Foo.new, Foo.new a.bar = b.bar = 1 a.baz = b.baz = 2

a == b # => true a.eql?(b) # => true a.hashcode == b.hashcode # => true

also reflexive and transitive, but not subclasses. Classes must be equal.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary (collapse)

Class Method Details

+ (Object) included(klass)



28
29
30
# File 'lib/instance_equality.rb', line 28

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