Module: ImmutableStructEx::Comparable

Defined in:
lib/immutable_struct_ex/comparable.rb

Overview

Makes a struct comparable with another struct or hash when extended.

Class Method Summary collapse

Class Method Details

.extended(struct) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/immutable_struct_ex/comparable.rb', line 7

def extended(struct)
  struct.instance_eval do
    def ==(other)
      return false unless other.is_a?(Hash) || other.is_a?(Struct)

      to_h == other.to_h
    end
  end
end