How can I collapse double splat arguments into nothing?

前端 未结 1 1658
南旧
南旧 2021-01-19 04:26

Splat-expanding an empty array in a method call effectively reduces the argument to nothing (empty parentheses added for clarity):

def foo()
end

def bar(*ar         


        
相关标签:
1条回答
  • 2021-01-19 04:39

    Try the below:

    def baz()
    end
    
    def qux(**opts)
        baz(*opts)
    end
    
    qux
    

    To see a bit more about how *hash works try the below:

    h = {}
    puts h # {}
    puts *h # nothing output 
    puts **h #{}
    
    0 讨论(0)
提交回复
热议问题