Reason #40 • February 9th, 2026

End-of-line conditionals

One of the most distinctive idioms in Ruby is putting conditionals at the end of one-line statements:

Ruby
puts "Hello, world!" if greeting_enabled?
      
JavaScript
if (greetingEnabled()) console.log("Hello, world!");
      

The most common use case for this is probably in guard statements at the beginning of methods, which either raise an error or return early if a condition isn't met:

Ruby
def pet_cat(cat)
  raise ArgumentError, "gotta provide an actual cat" if cat.nil?

  return if cat.sleeping?

  # Pet the cat...
end
      
JavaScript
function petCat(cat) {
  if (cat === null) throw new Error("gotta provide an actual cat");

  if (cat.isSleeping()) return;

  // Pet the cat...
}
      

I don't believe there are any objective technical arguments for why either style is superior to the other. Programmers would likely prefer either one based on what they're used to more than anything else. But it perfectly fits the Ruby philosophy that the code is targeting humans rather than machines.

In conversational human language, we usually state the condition at the end of sentences. When writing Ruby code, we tend to aspire to making our code read like natural language, and end-of-line conditionals help us achieve that.

History

Postfix conditionals (as this is academically named) have been part of Ruby since its inception. The inspiration most likely came from Perl, the only pre-Ruby language I'm aware of that had this feature.

Perl had postfix conditionals all the way from its initial release in 1987.

After Ruby, Crystal is the only other language I know of that has postfix conditionals.