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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -