I have this code
args = x.lead_details.last.leads.last.country_id rescue nil
Function(args)
I have used rescue keyword to make sure I don't get errors like
undefined method `country_id' for nil:NilClass,
undefined method `leads' for nil:NilClass
Is there any better way I can achieve this?
Other approach is
Function(x.lead_details.last.leads.last.country_id if x.present? && x.lead_details.present? && x.lead_details.last? && so on)