Ruby on Rails
PhpArray_diff_uassoc

The ruby way to do this is to work with custom classes or override functions of core classes to get the appropriate functionality.

Note: when using custom base classes, Array#— first checks the #hash function to see if two objects are equal. Then uses #eql? so you will have to override both to get the appropriate functionality.

For the below example, we could do this to introduce a custom comparison function.


class CustomArray < Array
  def initialize(array)
    #coverts any internal arrays to CustomArray
    array.each_with_index do |value, index|
      if value.is_a? Array
        array[index] = self.class.new(value)
      end
    end

    super(array)
  end

  def eql?(b)
    #this is the user supplied function
    if self == b
      true
    end
  end
end

hash1 = {0=>"red", "a"=>"green", "b"=>"brown", "c"=>"blue"}
hash2 = {0=>"yellow", "a"=>"green", 1=>"red"}
p Hash[*(CustomArray.new(hash1.to_a) - CustomArray.new(hash2.to_a)).flatten]