Never forget hashes or hash like objects such as session can have nil and therefore will break method chains

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the ruby category.

Last Updated: 2024-11-23

I had the following code:

tracking_info: session[:tracking_info].symbolize_keys

Sometimes the tracking_info is available in the session... but sometimes not. The code blew up in such cases, since symbolize_keys is not defined on nil.

Here's the fix:

tracking_info: session[:tracking_info]&.symbolize_keys