【问题标题】:How to get a newline for ruby string in the array如何在数组中获取 ruby​​ 字符串的换行符
【发布时间】:2018-01-03 01:37:24
【问题描述】:

我正在尝试用换行符在数组中输出两个值。

list = []
list << "hello"
list << "\n";
list << "testing"
puts "#{list}"

这将给出hello\ntesting,而不是以下输出:

hello
testing

如何用换行符输出这个数组?

【问题讨论】:

标签: ruby


【解决方案1】:
puts "#{list}"

这会将数组按原样打印为字符串。

puts list

这将在新行中打印数组的每个元素。这可能是您正在寻找的。​​p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多