gpt4 book ai didi

ruby-on-rails - 在 Ruby On Rails 中重构模型方法

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

我阵营在rails中常用的一个成语如下:

def right_things(all_things, value)
things = []
for thing in all_things
things << thing if thing.attribute == value
end
return things
end

我怎样才能让它变得更好/更快/更强?

谢谢

-C

最佳答案

def right_things(all_things, value)
all_things.select{|x| x.attribute == value}
end

关于ruby-on-rails - 在 Ruby On Rails 中重构模型方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/711823/

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