tc = order.total_cost.to_f rescue nil
msg.totalCost = tc if tc
here is total_cost retrieved (order.total_cost.to_f rescue nil), validated (if tc) and assigned (msg.totalCost = tc). I wonder whether all the operations could be made in one line without having to retrieve order.total_cost twice (assume that retrieval is a heavy time consumer operation).