Sha256: d53350e9e9bebb8b74ef0b75e3296e406a37c31417964614e1f91a7e95b63153

Contents?: true

Size: 409 Bytes

Versions: 16

Compression:

Stored size: 409 Bytes

Contents

# frozen_string_literal: true

module ImmutableStructEx
  # Makes a struct comparable with another struct or hash when extended.
  module Comparable
    class << self
      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
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
immutable_struct_ex-1.0.11 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.10 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.9 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.8 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.7 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.6 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.5 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.4 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.3 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.2 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.1 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-1.0.0 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-0.3.0 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-0.2.3 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-0.2.2 lib/immutable_struct_ex/comparable.rb
immutable_struct_ex-0.2.1 lib/comparable.rb