You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: two_sum.rb
    path of file: ./repos/Ruby/data_structures/hash_table
    
    the code of the file until where you have to start completion: # Challenge name: Two Sum

    
def two_sum(nums, target)
  hash = {}

  # create a hash to store values and their indices
  nums.each_with_index do |num, i|
    hash[num] = i
  end

  # iterate over nums array to find the target (difference between sum target and num)
  nums.each_with_index do |num, i|
    difference_target = target - num

    return [i, hash[difference_target]] if hash[difference_target] && hash[difference_target] != i
  end
end