I need a better hobby« an older post
a newer one »Consistency

How many different ways can you miss the ternary?

Blog

Yeah, so, I can totally recognize ternary operators when they are of the ? : format:

shadow = shadow.nil?  ? create_shadow() : shadow;

Yes, it's a shortcut for some variant of

if (shadow == nil) {
  shadow = create_shadow();
} else {
  // like anyone would do this
  shadow = shadow;
}

When they are of the if syntax, though, wow, does this read poorly to me:

shadow = if is_shadowing?(master)
       master.enable_shadow
     else
       master.disable_shadow
     end

And, yet, this is valid syntax in ruby, and most ruby developers are "Sure, that looks fine."

Add new comment