I\'m trying to get a common element from a group of arrays in Ruby. Normally, you can use the & operator to compare two arrays, which returns elements
Why not do this:
def get_common_elements_for_hash_of_arrays(hash) ret = nil hash.each do |key, array| if ret.nil? then ret = array else ret = array & ret end end ret = Array.new if ret.nil? # give back empty array if passed empty hash return ret end