选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x
当我在irb中创建一个新的数组/散列时,它会打印出一种很好的格式来显示结构,例如。["value1","value2","value3"]{"key1"=>"value1"}...但是当我尝试使用puts打印出我的变量时,我将它们折叠起来:value1value2value3key1value1我发现puts不是我想要的正确命令,但什么是?我希望能够以第一种格式而不是第二种格式在irb中查看我的变量。 最佳答案 您可以使用inspect方法:a=["value1","value2","value3"]putsa.inspect或者,