Choose the Right Control Structure

Posted: March 15, 2011 in Reading
Tags: , ,

Just some notes after reading “Eloquent Ruby” chapter two.

  • use unless in place of if not
  • use until in place of while not

You should think that do sth in the unless or until block unless/until condition is true.

Use each, Not for

Case statements use the === operator to do the comparisons. Since classes use === to identify instances of themselves, you can use a case statement to switch on the class of an object. And you can use a case statement to detect a regular expression match.

only false and nil are treated as false, you should avoid testing for truth by testing for specific values.

@first_name ||= '' shorter than @first_name = '' unless @first_name

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s