我可能试图对此进行努力。我试图格式散列键和值的数组输出给用户。 Ruby-doc为我提供了一个值的代码。 http://www.ruby-doc.org/core/classes/Hash.html#M002861将键和多个值分开以便打印。每个
h = { "a" => 100, "b" => 200 }
h.each {|key, value| puts "#{key} is #{value}" }
我试图让
h = { "a" => [100,'green'], "b" => [200,'red'] }
h.each {|key, m,n| puts "#{key} is #{m} and #{n}"}
produces:
a is 100 and green
b is 200 and red
我有一些运气 h.each {|键,M,N |把 “#{}键为#{[M, 'N']}”
it produces:
a is 100green
b is 200red
我需要我的元素的数组之间的一些空间,我怎么去这样做?
耶的解构绑定! – 2009-11-14 00:59:00