Changes

Jump to: navigation, search

Ruby Flow Control

250 bytes added, 21:15, 19 November 2007
The Ruby Ternary Operator
Ruby uses something called a ''ternary operator'' to provide a shortcut way of making decisions. The syntax of the ternary operator is as follows:
[condition] ? [true expression]:[false expression]
The way this works is that [condition] is replaced with an expression that will return either true or false. If the result is true then the expression that replaces the [true expression] is evaluated. Conversely, if the result was false then the [false expression] is evaluated. Let's see this in action:
=> "Hello Fred"
</pre>
 
== Summary ==
 
In this chapter of [[Ruby Essentials]] we have explored the various control structures with allow us to build decision making logic into our Ruby programs. In the following chapter we will look and constructing [[Looping in Ruby]].

Navigation menu