1. Technology
Send to a Friend via Email

Convoluted Constructions

A "convoluted construction" is any statement whose purpose cannot immediately be determined. While Ruby gives you the tools to avoid convoluted constructions, they're out there, and some of them are in regular use.

The Curious Case of the Flip-Flop
The Flip-Flop operator is in itself a convoluted construction. Part range, part conditional, and perhaps one of the more confusing features of Ruby.

Convoluted Constructions: a ||= b > x
Some programmers try to fit as much logic into a single statement as possible, often using the most concise syntax available. While this often takes some clever constructions, it's usually not apparent what the code does. This type of thing is profoundly un-Ruby, and something you'll see in a language like Perl more often. However, it does show up in Ruby code from time to time.

Convoluted Constructions: a = 1, b = 2
Given the expression a = 1, b = 2, what will a and b be equal to? What will their types be? Why?

You can opt-out at any time. Please refer to our privacy policy for contact information.

©2014 About.com. All rights reserved.