gpt4 book ai didi

ruby - 基本 ruby 问题 : the { } vs do/end construct for blocks

转载 作者:数据小太阳 更新时间:2023-10-29 08:17:57 26 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
Using do block vs brackets {}
What is the difference or value of these block coding styles in Ruby?

为什么:

test = [1, 1, 1].collect do |te|
te + 10
end
puts test

有效,但无效:

puts test = [1, 1, 1].collect do |te|
te + 10
end

然而这有效:

puts test = [1, 1, 1].collect { |te|
te + 10
}

我不知道的 block 的 do/end 结构和 { } 结构之间有区别吗?

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