In .Net there is one option for null values like a = a ?? "" + "some string value"
This means if a is null take a as "" this. I want to know is there any thing like this in ruby.
In Ruby, you can do:
a ||= ''
this means that if a is nil or false, empty string would be assigned to it. Note that this is an expression that returns eventual value of a.
If you want to prepend/append it to a string, best thing to do is:
a.to_s + "some string value"
This will automatically handle even the nil values.
a = nil
a.to_s
# => ""
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