Intern Track Roadmap

Ruby logic: standard checks

This course covers conditional logic in Ruby. It starts with the full if, elsif and else block and shows that every if is an expression with its own value. It then covers unless and why pairing it with else is discouraged. Next come the &&, || and ! operators, short-circuit evaluation and the precedence trap in the word versions and and or. It also presents case and when as an alternative to long elsif chains. It ends with a small access-control challenge.

What you'll learn

  • ✓Writing if, elsif and else blocks and using them as expressions
  • ✓Using unless as a guard clause and avoiding unless with else
  • ✓Combining conditions with &&, || and !
  • ✓How short-circuit evaluation makes the order of conditions matter
  • ✓Why and and or bind more loosely than &&, || and assignment
  • ✓Matching one value against ranges, classes and lists with case and when
Free preview · Lesson 1 3 min read

if, elsif, else: the full shape

if as a trailing modifier showed up in Ruby: programmer happiness. Ruby methods & returns used full if/elsif/else blocks in classify and check_age without naming the shape. This course covers it fully: conditionals, &&, || and the standard checks every Ruby program relies on.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...