gpt4 book ai didi

ruby-on-rails - "use this if it isn' t 空白的 Ruby 速记,否则使用那个“

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

我有以下代码:

url = file.s3_url.blank? ? file.url : file.s3_url

有没有更短的写法?

谢谢!

最佳答案

在 ActiveSupport 中有一个抽象,Object#presence :

url = file.s3_url.presence || file.url

关于ruby-on-rails - "use this if it isn' t 空白的 Ruby 速记,否则使用那个“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4994354/

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