Beautiful Ruby

When coding, I often have the need for a statement along the lines of:

print (string_a != nil) ? string_a : string_b

i.e. print string_a unless it’s nil, then print string_b.

In ruby, I figured there must be a neater way, so I tried:

print string_a or string_b

and it worked. Wow. So neat. So awesome…! =D

Leave a Reply

Your email address will not be published. Required fields are marked *