Answer the question
In order to leave comments, you need to log in
Array.to_s and single quotes?
Hello. How can an array be convected into a string so that the values are in single quotes.
Through gsub , you can then make a replacement, but maybe there is a better solution? Thanks
children_code = ['000000012','000000013','0000000147','000000015','000000016','000000017','000000018']
puts children_code.to_s
# ["000000012", "000000013", "0000000147", "000000015", "000000016", "000000017", "000000018"]
# Вот так работает
puts children_code.to_s.gsub( '"', '\'' )
# ['000000012', '000000013', '0000000147', '000000015', '000000016', '000000017', '000000018']
Answer the question
In order to leave comments, you need to log in
It is possible like this:
or the same written differently:
puts "[%s]" % children_code.map{|cc| "'#{cc}'"}.join(',')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question