Last Updated: February 28, 2019
·
339
· msz

Cast variable to string unless it's nil in Ruby 2.3+

irb(main):001:0> var = nil
=> nil
irb(main):002:0> var&.to_s
=> nil
irb(main):003:0> var = 5
=> 5
irb(main):004:0> var&.to_s
=> "5"