Ruby Arrays and Hashes

In Ruby, an array is an ordered collection of objects, which can hold multiple data types, including numbers, strings, other arrays, or even objects. Of the languages we’ve looked at, it is most similar to lists in Python, where you can store dynamic types, and they are dynamically sized. There are a couple of ways…

Repetition with Ruby

The Ruby method each allows you to iterate over a list of items. This is essentially a for-each style of loop and is like JavaScript’s each method. Notice that the iterative value is placed inside of two pipe (|) characters. You don’t have to put everything on one line. In fact, you can’t if you have multiple…

Classes in Ruby

Classes do not have to be in a separate file as you can see from the file below. Let’s look at a class, then break it down. Class Definition As with most languages, you use class to define your class definition, and class names typically start with a capital letter. As with conditions, and other…

Advanced Logic in Ruby

In addition to the basic programming logic that Ruby has, it also has a few weirder forms of logic it can employ. Single Line Conditions Ruby allows for single line conditions where it is almost like a short hand. However, doing so may seem backward to normal logic, because the true block goes first. Consider…