Богдан, в целом ваше решение рабочее.
Но я не рекомендовал бы вам увлекаться «однострочниками».
# encoding: utf-8
# @see https://toster.ru/q/447239
require 'date'
# @param [Hash] source
# @return [String]
def main(source, equal = ' = ', separator = ', ', result = [])
source.map do |key, value|
case value
when String, Date
value = %Q('#{value}')
when Fixnum, Bignum, Float
else
raise "Wrong class for #{value}"
end
result << "#{key}#{equal}#{value}"
end
result.join separator
end
# passed
# tstr='foo',tnbr=42,tdate='2017-12-18'
source = { tstr: 'foo', tnbr: 42, tdate: Date.today }
puts main source, '=', ','
# passed
# tstr = 'foo', tnbr = 42.42, tdate = '2017-12-18'
source = { tstr: 'foo', tnbr: 42.42, tdate: Date.today }
puts main source
# failed
source = { tstr: %w(foo), tnbr: 42, tdate: Date.today }
puts main source