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: gradient.rb
    path of file: ./repos/app_perf/lib
    
    the code of the file until where you have to start completion: ########################################################
    
  def to_hex(color)
    # Converts color to a Hex value
    case
    when is_hex?(color) then color
    when is_rgb?(color)
      color.inject("#") do |memo, value|
        str = value.to_i.to_s(16)
        hex = str.length==1 ? str.concat(str) : str
        memo.concat(hex)
        memo
      end
    else raise "#{color.inspect} is not a valid RGB or Hex color"
    end