How do i reduce the following code to one line in Ruby?
unless(current_facebook_user.nil?)
unless(current_facebook_user.client.nil?)
unless(current_facebook_user.client.default_params.nil?)
val = current_facebook_user.client.default_params
end
end
end
You can using the
try()method fromactive_support/core_ext/object/try.rbintroduced since Rails 2.3.2Method Try
Or directly using Safe navigation operator introduced since Ruby 2.3.0
documented here
more on Safe navigation operator