Sha256: bad4f606fa9638e67556a9886f01e2c6bbe3ce80dee6c989e51f3df4f90eaeea

Contents?: true

Size: 666 Bytes

Versions: 5

Compression:

Stored size: 666 Bytes

Contents

class SiteHub
  module Equality
    module ClassMethods
      def transient_fields
        @transient_fields ||= []
      end

      def transient(*fields)
        transient_fields.concat(fields.collect { |field| "@#{field}".to_sym })
      end
    end
    def self.included(clazz)
      clazz.extend(ClassMethods)
    end

    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

    def _clazz
      self.class
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sitehub-0.4.10 lib/sitehub/equality.rb
sitehub-0.4.9 lib/sitehub/equality.rb
sitehub-0.4.8 lib/sitehub/equality.rb
sitehub-0.4.7 lib/sitehub/equality.rb
sitehub-0.4.6 lib/sitehub/equality.rb