我有这个哈希:
arr={ [0,1]=>[0,0,1,1], [0,2]=>[0,1,0,1], [0,3]=>[0,1,1,0], [1,2]=>[1,0,0,1], [1,3] =>[1,0,1,0], [2,3] => [1,1,0,0] }
我想把它分成两行,因为它很长,有 121 个字符。我不是线长的贴纸,但我的指导线是 80,这比我喜欢的要长
所以我试过了
arr={ [0,1] => [0,0,1,1], [0,2] => [0,1,0,1], [0,3] => [0,1,1,0] }
arr.merge({[1,2] => [1,0,0,1], [1,3] => [1,0,1,0], [2,3] => [1,1,0,0]})
但是我的测试失败了,错误如下
undefined method `[]' for nil:NilClass
我怎样才能更好地打破它?一种选择是行延续
\
但这看起来并不特别整洁。arr={ [0,1]=>[0,0,1,1], [0,2]=>[0,1,0,1], [0,3]=>[0,1,1,0], \
[1,2]=>[1,0,0,1], [1,3] =>[1,0,1,0], [2,3] => [1,1,0,0] }
虽然我想我可以做到
arr={ [0,1]=>[0,0,1,1], [0,2]=>[0,1,0,1], [0,3]=>[0,1,1,0], \
[1,2]=>[1,0,0,1], [1,3] =>[1,0,1,0], [2,3] => [1,1,0,0] }
但这看起来像是缩进的空白维护气味。
有更简洁的选择吗?
最佳答案
arr = {
[0,1] => [0,0,1,1], [0,2] => [0,1,0,1], [0,3] => [0,1,1,0],
[1,2] => [1,0,0,1], [1,3] => [1,0,1,0], [2,3] => [1,1,0,0]
}
关于ruby - 如何将长的 ruby 散列分成多行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23728367/