Code Pointers #07 — setting variables based on if-else statements

I came across some really lovely syntax that I wanted to record here.

value = if true
value                                          #=> true_value

I’d seen this before but hadn’t taken the time to fully understand it.

It is equivalent to this:

if true
value = :true_value
value = :false_value

But you can see how the first version is more DRY (do not repeat yourself) and more readable.

A single golf clap? Or a long standing ovation?

By clapping more or less, you can signal to us which stories really stand out.