Module: Id3Taginator::Extensions::Comparable

Overview

offers compare methods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

compares all Comparables using the defined compare method

Parameters:

  • other (Object)

    the object to compare with

Returns:

  • (Boolean)

    true if equal, else false



23
24
25
# File 'lib/id3taginator/extensions/comparable.rb', line 23

def ==(other)
  compare(self, other)
end

#compare(obj1, obj2) ⇒ Boolean

compares the instance variables of 2 objects for equality

Parameters:

  • obj1

    object 1

  • obj2

    object 2

Returns:

  • (Boolean)

    true if both instance variables are the same, else false



11
12
13
14
15
16
17
18
# File 'lib/id3taginator/extensions/comparable.rb', line 11

def compare(obj1, obj2)
  is_same = true
  obj1.instance_variables.each do |it|
    is_same = false if obj1.instance_variable_get(it) != obj2.instance_variable_get(it)
  end

  is_same
end