如何在红宝石中打印多维数组? [英] How do I print a multi-dimensional array in ruby?
本文介绍了如何在红宝石中打印多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ruby中打印多维数组的首选方法是什么?
What's the preferred method of printing a multi-dimensional array in ruby?
例如,假设我有这个2D数组:
For example, suppose I have this 2D array:
x = [ [1, 2, 3], [4, 5, 6]]
我尝试打印它:
>> print x
123456
还有什么是行不通的:
>> puts x
1
2
3
4
5
6
推荐答案
如果您只是在寻找易于阅读的调试输出,则"p"很有用(它在数组上调用inspect())
If you're just looking for debugging output that is easy to read, "p" is useful (it calls inspect() on the array)
p x
[[1, 2, 3], [4, 5, 6]]
这篇关于如何在红宝石中打印多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文