Join values from ruby array but keep their type -
i've got array :
a = [27624, 22, 33, "ema", "test", 11, nil]
when a.join(',')
1 bing string values joined. how can same effect strings retain type. output should :
"27624, 22, 33, 'ema', 'test', 11"
a.map{|e| e.is_a?(string) ? "'#{e}'" : e}.join(',')
alternatively: (this may not have desired effect - particularly nil
, other types haven't included here)
a.map(&:inspect).join(',')
Comments
Post a Comment