是否有一些函数或语法结构使下一个例子有效?
Hash#values_at使用Array参数调用函数:
h = {"a" => 1, "b" => 2, "c" => 3}
ary = ["a", "b"]
h.values_at(*ary) # Error: argument to splat must be a tuple, not Array(String)
Run Code Online (Sandbox Code Playgroud)
传递Hash给初始化类或结构:
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
h = {"x" => 1, "y" => 2}
Point.new(**h) # Error: argument to double splat must be a named tuple, not Hash(String, Int32)
Run Code Online (Sandbox Code Playgroud)