1. About.com
  2. Computing & Technology
  3. Ruby

Control Structures

Often ignored or only glossed over, control structures and loops are very important to master. While they're very straightforward in languages such as C, there are several subtleties to understand before you can really leverage the conditional and loop statements in Ruby.

Learning Control Structures
Ruby Spotlight10

Partitioning Strings

Thursday January 26, 2012

The 'split' method isn't the only fish in the sea.  The 'partition' method is similar, but doesn't consume the split string.

The Curious Case of the Flip-Flop Operator

Thursday January 26, 2012

The Flip-Flop operator is an odd thing.  It uses the range syntax, but doesn't produce a Range object.  Sometimes, it's true, sometimes it's false, but most of the time it's just confusion.  Should you be using it in your code?  That's up to you, but you really should know about the flip-flop operator, should you ever encounter it.

Ranges

Tuesday January 24, 2012

Most languages don't have any concept of a "range."  To iterate over some numbers, you either define a minimum and maximum and iterate with a typical loop, or use a combination of comparison operators.  Ruby, on the other hand, has Ranges out of the box, and they can be used in a number of intuitive ways.

Read all about Ranges here.

Using the Enumerable Module

Thursday January 19, 2012

Did you know that you can make any of your classes act like Ruby collections?  You can use any of the methods you'd typically use on collections (like Arrays and Hashes) on your classes by simply implementing the each method and including the Enumerable module.  Also, if the elements of your collection implement the spaceship (<=>) operator, your collection can even be sorted!

Read more about using the enumerable module.

Discuss in my forum

©2012 About.com. All rights reserved. 

A part of The New York Times Company.