gpt4 book ai didi

ruby:此语法的名称,它拆分块的位置参数

转载 作者:数据小太阳 更新时间:2023-10-29 07:53:28 24 4
gpt4 key购买 nike

今天看到一段代码

#! cruby 1.9
lam = lambda do |(a,b),c|
#blahblah
end

它看起来等于

lam = lambda do |l,c|
a,b = *l
#blahblah
end

这个语法有“官方名称”吗?

最佳答案

是的,它叫做destructuring .

So what is destructuring? The most concise definition I found is from Common Lisp the Language. Destructuring allows you to bind a set of variables to a corresponding set of values anywhere that you can normally bind a value to a single variable. It is a powerful feature of Clojure that lets you write some very elegant code. For more information about Clojure's features, I recommend you check out Jay Field's blog post on the subject. While destructuring in Ruby is not quite as powerful as Clojure, you can still do some cool stuff.

关于ruby:此语法的名称,它拆分块的位置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14169605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com