Ruby 'Unless' Goes Mainstream

I don’t like or not a fan of Ruby’s ‘unless’ keyword. I mean its nice but it take time to get used to.

Sample ‘unless’ statements like this:

1
puts product.name unless product.name.nil?

The code statement above is nice and easy. I’d say that in english “Print the product’s name unless the product doesn’t have a name”.

Why do we need unless? Let replace it with something else:

1
2
3
4
5
class Object
  def not_nil?
    !nil?
  end
end

Then we can code:

1
puts product.name if product.name.not_nil?

So far so good, that’s much better, ‘unless’ never made it into mainstream language.
OO scripting languages like Ruby can make new keyword. :)