gpt4 book ai didi

Ruby 对象批量赋值

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

有没有更好的方法来执行下面的代码?

user.name = "abc"
user.email = "abc@test.com"
user.mobile = "12312312"

像这样的事情会做:

user.prepare do |u|
u.name = "abc"
u.email = "abc@test.com"
u.mobile = "12312312"
end

最佳答案

tap让我们来做吧:

user.tap do |u|
u.name = "abc"
u.email = "abc@test.com"
u.mobile = "12312312"
end

关于Ruby 对象批量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906676/

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