[英]Force Literal ASCII character into string
I'm generating the following array for use in a JS charting library: 我正在生成以下数组,以用于JS图表库:
['DE', 50], ['GB', 9], ['IE', 2]
However, I need to force in the literal apostrophe so that the JS library renders the chart correctly. 但是,我需要强制使用文字撇号,以便JS库正确显示图表。 ie ['DE', 50], ['GB', 9], ['IE', 2] 即['DE',50],['GB',9],['IE',2]
I'm sure this is simple, but I just keep ending up with the ASCII codes. 我敢肯定这很简单,但我一直以ASCII码结尾。
My Ruby code is 我的Ruby代码是
@product.sales_data.map { |territory,sales| "['" << territory << "', " << sales.to_s << "]" }.join(", ")
This works fine in ruby 2.0.0 at least 至少在ruby 2.0.0中工作正常
sales_data = [['DE', 50], ['GB', 9], ['IE', 2]]
sales_data.map { |territory, sales| "['" << territory << "', " << sales.to_s << "]"}.join(", ")
or alternatively 或者
sales_data.map { |territory, sales| "['#{territory}', #{sales}]" }.join(", ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.