App Academy

Tic Tac Toe - interesting comparison syntax

Hi, I ran across the following syntax while checking my Tic Tac Toe project against the solution.

is_computer ? ComputerPlayer.new(mark) : HumanPlayer.new(mark)

I’d like to read up more on this notation which seems to be a cleaner alternative to using an if statement.
Anyone have any idea what this notation is called?

Thank you,
Michael

Hi Michael,
That notation is called the Ternary Operator - you can check it the docs here.

Thank you Jesse! Looking forward to using the shorthand more often :slight_smile:

1 Like