Aurimas Aurimas - 1 year ago 73
Ruby Question

Ruby equivalend to Coffeescript shortened version of shorthand if operator?

How can you do this in Ruby?

In coffeescript you can do

name = a ? "bear"

Answer Source

Boolean or:

name = a || "bear"

To be precise, the following is an exact equivalent (there is no undefined in ruby):

name = a.nil? ? 'bear' : a
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download