Ruby Monstas


Programming workflow

Programming workflow

Programming workflow

  1. Think about what you want to do
  2. Switch to your editor
  3. Edit the code
  4. Save the file
  5. Switch to the terminal
  6. Run your code
  7. Watch what it does
  8. Go to 1.

Command line

Command line

Is always in a working directory

You can do most things you can do in a graphical interface

You can do a lot of things quicker than with a graphical interface (once you’ve practiced a bit)

Command followed by arguments (separated by spaces)

Cryptic commands might seem scary at first

Basic command line commands

pwd
stands for 'print working directory'

cd
stands for 'change directory'

ls
stands for 'list' the files and folders in directory

Working directory

...is the folder where you currently are

pwd
prints out your working directory,
ls
lists all files and folders

cd
changes the directory and
ls
lists all files and folders

cd rubymonstas/se2
changes the directory directly to se2

How to use cd command

cd YOUR-FOLDER
changes your working directory to the selected folder

cd YOUR-FOLDER/ANOTHER-FOLDER
changes your working directory to the selected folder

cd ..
takes you one level up

cd ../..
takes you two levels up

Command line history and autocompletion

You can access the history of previous commands you entered with

Go back and forth with and

You can autocomplete the name of the file with Tab

Try it now!

Hello world, again!

  1. Open your editor (Visual Studio Code)
  2. Create a new file (Ctrl + N or ⌘ + N)
  3. Type:
    puts "Hello world, again!"
  4. Save the file as
    hello_world.rb
    (Ctrl + S or ⌘ + S)
    Important: Know in what directory you saved the file!

Hello world, again!

  1. Open the terminal ("Powershell" or "Terminal")
  2. Change to the directory using the
    cd
    command (use Tab for autocompletion of directory names)
  3. Run your code:
    ruby hello_world.rb

Frustration curve

To avoid the frustration curve

Make tiny changes (ideally only on one line)

Check if it works right away

If it doesn't, think about why (read error messages closely)

Repeat!

IRB and command line are two different worlds

IRB lives in the terminal but you use ruby language

You can have multiple terminals open: one with irb and one with the command line.

Entering and exiting IRB

You enter IRB by typing

irb

You exit IRB by typing

quit
or
exit
or pressing Ctrl + D

Additional Resources

Ruby For Beginners: Terminal

Ruby For Beginners: Programming workflow

What questions do you have?