2017-10-06 109 views
3

我是Ruby/Ruby on Rails的新手。我寫了下面的代碼從api獲取布爾值。 API調用失敗,並且它去救援塊。但由於某種原因,它將該值設置爲true。我不明白這是怎麼發生的。Ruby變量值設置爲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 

回答

6

軌道記錄器上成功登錄返回true

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

因爲這是在該方法中執行的最後一行時,該值是返回紅寶石有隱含的回報。

+2

正確的,你仍然可以返回不管你從急救塊的願望。 – whodini9

+0

哦,謝謝!應該想到這一點。 – NewQueries

1
Rails.logger.error(string) 

返回true,可以看出:

2.3.1 :002 > Rails.logger.error('foo') 
foo 
=> true