C# has a null-conditional operator that works like this
SomeObject?.SomeParam
If SomeObject is null, then the result of that expression will be null rather than throwing a null reference exception. Does something like this exist in Ruby?
Yes. Use &. to call a method.
some_value&.some_method
If some_value is nil, then some_method will not be executed, and the return value of the expression will be nil. Otherwise, some_method will be called as with when called with ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With