Last post I touched on the history of Ruby and the creator. As well as simple commands that would get you started writing simple Ruby programs. I am hoping that this post comes across as understandable as possible, because I will be getting into debugging your program, and what many of the keywords mean guiding you through what your test is telling you and how to fix it.

Using the IRB platform or Interactive Ruby, we are able to write Ruby commands directly into terminal, and execute your program. This is a Ruby Shell or REPL which stands for Read Evaluate Print Loop; think of it as a Ruby playground. Its purpose is for testing, playing, and manipulating your code for further understands. To begin simply type IRB (irb) into your terminal.

This is where you can test your code without changing the file you are actually working on, or test your program to see the result. Below you will see simple mathematical equations using puts (out*put s*tring) to output the string you want to display.

When you are writing code you will see a ton of error messages. This is expected! Something that I personally had to get over was not hiding from these, but viewing them as a clue to find where my logic is semantically incompatible. Errors in a program are a great tool to embracing and understanding, and understanding what they are telling you will help you build better tools. Error messages, for the most part, display three simple messages; where, why, who.

Where: Location of error

Why: The description

Who: The type of error

The “where” is the location of the error. Within the learn.co IRB text editor supplied by Flatiron, my simple error looks like the world may end…. But that is because a RSPEC test file is attached, which we will get into later but basically all you need to look at what I placed below.

Because the a RSPEC test suite file is attached you have to read the error a little differently. These are test applied specifically to your program within each assignment within the school, making your life easier when debugging your program. Generally tests found though Flatiron School call on the method you define in your programs and check to see if they are working the way you expect them to. But the test above states what error has failed “SyntaxError” and what is supposed to return true “unterminated string meets end of file” stating that the string was not terminated within your program properly. Terminating the string within this specific lesson will return true and pass the RSPEC test suite and allow you to continue learning through Flatiron School.

Flatiron School setting up their lessons this way is greatly beneficial to the student and one of my favorite parts about the school. It allows me as the student to navigate through the lessons test suite incrementally, until I have reached a resolution to pass the the course material. Keep in mind that the test suite usually returns four common error types.

Name Errors: Are caused when a given name is invalid or undefined.

Syntax Errors: They are the result of incorrect syntax.

Type Errors: When you try to do a mathematical operation on two objects of a different type. Ex: 2 + “2” = ERROR

Division Errors: Are caused when a given number is divided by zero.

I know when I first looked at all these errors, all I saw was gibberish. But once I understood what the return values meant that were being returned, everything made a lot more sense. We are almost ready to begin writing code! Haha

Keep in mind, just like most other programming languages there are roughly six different data types know as classes in Ruby which are booleans, symbols, numbers, strings, arrays, and hashes.

Booleans: The two values of the boolean data type are true and false. But, in Ruby there is actually no such thing as a boolean class, instead every appearance or instance of true and false in your program are instances of the true class and false class.

Numbers: For those of you who failed math, like me, integers are numbers. There are two types of numbers:

Fixnums: Whole numbers, like 8

Floats: Decimal Numbers, like 8.4

Symbols: A symbol is a representation of a piece of data

Arrays: Arrays are a collection of Ruby objects. Arrays can also store any type of data.

Hashes: Hashes store objects in Ruby, and operate kind of like a dictionary composed of key value pairs

I know this was a lot of definitions, but understanding the basic concept of what a language is comprised of and how to read output values is a key to furthering learning. Most of the concepts above can be transferred to many other programming languages and are pretty universal. Even though we did not get to cover very much code in this section of Flatiron School, I did get to walk away with the tools to understand future issues that may arise.