What To Expect From This Course

Get an introduction to the course and its intended audience.

Introduction to programming in Ruby

Programming is a way to teach a computer how to do something the way the programmer thinks it should be done. Put another way, programming is a description of how to perform some process.

The programmer describes the process by writing some text called source code. The computer reads and analyses the code to execute it successfully.

Code is made of words, and the sequence of words must follow some rules. Some words are special. We say that the text is written in some language or, more precisely, some programming language.

Both the words and the rules may differ depending on the programming language, like spoken languages.

The text follows basic grammar rules, usually much stricter than spoken languages to allow the computers to easily understand them. Breaking the rules when writing the source code leads to invalid text which the computer cannot understand. In other words, no poetry is allowed when writing code.

A computer reads the code and does what the code asks it to do. It does this by recognizing some predefined words, word sequences, and the structure and is able to do so because the code applies the rules defined by the programming language. Usually, programming languages also allow programmers to set the definition of new words to help write the code.

In this course, we are going to program in Ruby, an increasingly popular programming language. A tool available on the computer, named the Ruby interpreter, understands the language and handles the code.

In the following sections, we are going to write, step by step, the code that is going to explain to the computer how to play the hangman game.

Who is the target audience?

This is a beginner-level course targeted toward anyone interested in learning to program in Ruby. Prior knowledge of basic operations is a plus but it’s not a requirement. We will be using Ruby for this course. In the following chapters, we are going to write the code that will tell the computer how to play the hangman game.

What is the hangman game?

The hangman game is a two-player game where the first player chooses an unrevealed word for the second player to guess.

The second player knows how many letters the word contains and tries to guess the possible letters one by one. If a letter is part of the hidden word, the first player reveals the position of the letter (if the letter appears several times, all positions are revealed). If the letter is not part of the word, the second player loses one chance.

The first player draws elements of the hanged man every time the second player proposes a wrong letter, starting with the head, then the torso, then the arms and legs. If the hanged man is complete, the second player loses the game.

Let’s have a demo of what we will be building in this course. Press the “Run” button to play the game!

require_relative 'gallows' 

draw_gallows 0
draw_gallows 1
draw_gallows 3
draw_gallows 6
draw_gallows 7
Hangman Demo