我试图配对两个键值对,但我不确定如何实现这一点.以下是我的尝试:
struc = Array[(3,4),(5,6)]
for i in 0..1
puts "#{struc[i,i]}"
end
Run Code Online (Sandbox Code Playgroud)
但我想要的输出如下(前一个代码块不生成):
3 4
5 6
Run Code Online (Sandbox Code Playgroud) 变量value的initialize方法LocationList填充在这些变化是由relected线014 print语句线015,但return在线路016认为哈希仍然是空的(向右滚动才能看到后返回值=>).
def random_point
x = rand * 2.0 - 1.0
y = rand * 2.0 - 1.0
until x**2 + y**2 < 1.0
x = rand * 2.0 - 1.0
y = rand * 2.0 - 1.0
end
return [x, y]
end
class LocationList < Hash
def initialize(node_list)
value = {}
node_list.each {|node| value[node] = random_point }
print value
return value
end
end
z = ["moo", "goo", "gai", …Run Code Online (Sandbox Code Playgroud)