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…

Basic Logic in Ruby

In Ruby, you’ll find that all of the standard logic operators that most languages have, are supported. Symbol Meaning < Less than > Greater than == Equals != Not equals >= Greater OR equal to <= Less OR equal to Conditionals Of course, conditionals such as an if statement are also possible within Ruby. Similar…

Your First Ruby Program

As with most languages, we always want to start with a “Hello World” program. Remember, this is to make sure everything is working, as much as it is to learn the programming language. For simplicity’s sake, we’re going to use the online editor: https://www.jdoodle.com/execute-ruby-online or https://www.onlinegdb.com/online_ruby_compiler You will notice right away that in Ruby, we…