gpt4 book ai didi

ruby-on-rails - Ruby 变量值设置为 true

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

我是 Ruby/Ruby on Rails 的新手。我写了下面的代码来从 api 获取 bool 值。 API 调用失败,它转到了 rescue block 。但出于某种原因,它将值设置为 true。我不明白这是怎么发生的。

@is_attached = OnDeck.api.check_is_attached(@decision.application_number, current_user)

API调用/客户端封装代码

def check_is_attached(app_number, user)
begin
client.check_is_attached(app_number, user.auth_token)
rescue OnDeckException::MerchantApiException => e
Rails.logger.error("Caught exception #{e} while calling check_mbs_attached for app_number : #{app_number}")
end
end

最佳答案

Rails 记录器在成功记录时返回 true:

[2] pry(main)> Rails.logger.error("Caught exception")
Caught exception
=> true

因为这是方法中执行的最后一行,所以该值作为 ruby​​ 具有隐式返回值而返回。

关于ruby-on-rails - Ruby 变量值设置为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46611868/

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