coffeescript模拟try()activesupport方法

asi*_*niy 4 javascript ruby-on-rails activesupport coffeescript

有非常有用的.try()rails方法,这对我有很多功能:

hash.try(:a).try(:b)
# equal to
# if hash.present? && hash.a.present?
#   hash.a.b
# else
#   nil
# end
Run Code Online (Sandbox Code Playgroud)

有没有类似于coffeescript的东西?

apn*_*ing 10

是:

hash?.a?.b
Run Code Online (Sandbox Code Playgroud)

the existential operator该文档