The Pragmatic Studio

Setup

Exercises

Welcome to your first exercise! We're delighted to have you along for the course.

This exercise will help you get everything set up on your computer so you're ready to start writing Ruby code in the next exercise!

1. Install Ruby

If you've taken our Ruby Programming course or you've previously done some Ruby programming, then you already have Ruby installed. If for any reason you need a fresh install of Ruby, check out our Ruby installation instructions.

We'll wait right here for you...

2. Choose a Code Editor

We trust you already have a favorite code editor at the ready for writing Ruby code. If not, we recommend using Visual Studio Code, or Sublime Text as we do in the videos. Both run equally well on Mac, Windows, or Linux.

3. Create a Project Directory and Starter File

To keep things organized, let's create a directory to hold the Ruby files you'll create during this course. We'll also create a starter Ruby program file and run it, just in case you need a quick refresher on how to do that.

  1. Start by creating a directory called blocks_course and change into this directory. The commands to do that are the same regardless of which operating system you're using, but the directory structure is slightly different.

    If you're running Mac OS X or Linux, create the blocks_course directory in your home directory (represented by the tilde character). To create the directory and change into it, type the following two commands:

    mkdir ~/blocks_course
    cd ~/blocks_course

    If you're running Windows, create the blocks_course directory in the top-level C:\ directory (represented by the backslash character) since Windows doesn't really have the concept of a user's home directory. To create the directory and change into it, type the following two commands:

    mkdir \blocks_course
    cd \blocks_course
  2. Next, create a new Ruby program file called block_basics.rb in your blocks_course directory.

    One way to create a new file is to use the File -> New File menu item of your text/code editor, and then save the new file using the File -> Save menu item. Make sure to save the file in the blocks_course directory we created in the previous step.

    Alternatively, if you're using Visual Studio Code, you can open a new file from the command line using the code command-line utility and giving it the name of the new file, like so:

    code block_basics.rb

    Or if you're using Sublime Text, you can open a new file from the command line using the subl command-line utility and giving it the name of the new file, like so:

    subl block_basics.rb

    This command opens the new file but doesn't save it, so make sure to save the file using the File -> Save menu item or standard keyboard shortcut.

  3. As a simple test, in your block_basics.rb file type in the following Ruby code to print a welcome message to the screen:

    puts "Let's start mastering Ruby blocks!"
    

    Don't forget to save the file!

  4. In the videos, we'll run Ruby program files from inside the Sublime Text editor just so it's quick and easy to see the result. If you're using Sublime Text, press Command+B on a Mac or Ctrl+B on Windows to run the block_basics.rb file. You should see "Let's start mastering Ruby blocks!" displayed in the output panel that appears beneath the main panel. To hide the output panel, hit the Escape key. Most Ruby-aware text editors and IDEs offer a way to run Ruby program files from within the editor.

    Of course you can also run Ruby program files from the command line. To do that, use the ruby command and pass it the name of your Ruby program file as the argument. For example:

    ruby block_basics.rb

    Again, in the videos you'll see us run the code inside the editor, but in the exercises you can run your code whichever way you prefer.

Great, now you're ready to start mastering Ruby blocks!

New to Ruby?

ruby

If you're new to the Ruby programming language, consider taking our Ruby course before you start this in-depth course on Ruby blocks. You'll learn all the fundamentals of the language and object-oriented programming while writing a full-featured Ruby program step-by-step from start to finish. Once you're comfortable with the basics of the Ruby language, you'll be in a much better position to master Ruby blocks.

Up Next...

When you hit the big green button below, you'll go directly to the next video in the course where we'll start writing Ruby blocks. You're certainly welcome to code along with us in the video if that helps you learn, but feel free to simply watch the video. Then, after watching the video, you'll find a corresponding hands-on exercise where you get to apply what you learned in the video. The exercise breaks down everything we did in the video in a step-by-step format with hints and solutions.

Let's jump right into it!

All course material, including videos and source code, is copyrighted and licensed for individual use only. You may make copies for your own personal use (e.g. on your laptop, on your iPad, on your backup drive). However, you may not transfer ownership or share the material with other people. We make no guarantees that the source code is fit for any purpose. Course material may not be used to create training material, courses, books, and the like. Please support us by encouraging others to purchase their own copies. Thank you!

Copyright © 2005–2024, The Pragmatic Studio. All Rights Reserved.