Skip to content


Subversion checkout URL

You can clone with
Download ZIP
User Input with Highline or Sinatra
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Week 3


Repetition is the key to success. The exercises proposed this week again ask you to fork, clone, and fix various examples. However this time the safety net has been taken out from underneath you.

Exercise Outline

  • Fork and clone this repository
  • Run the tests
  • Fix the failing tests

Choose Your Own Adventure


  • Use HighLine to make a simple quiz


  • Use Sinatra to create a simple website


  • How can you make what you do easier to do?


The exercise are laid out in the same way as before. A word of warning about this set of exercises: Both the Struct and OpenStruct examples require a little more use of your noodle. For those tests the goal is to change the subject of the test of the helper methods to support the expectations that are outlined.

So when a test states the following:

Person = :name

describe Person do

  subject { "Ivan" }

  it "should have a role" do
    subject.should respond_to :role

  it "should have the correct role" do
    subject.role.should == :teaching_assistant


Your job would be to change the Struct to make the tests pass:

# Added the role here to the struct
Person = :name, :role

describe Person do

  # Added the role value here when creating the Person
  subject { "Ivan", :teaching_assistant }

  it "should have a role" do
    subject.should respond_to :role

  it "should have the correct role" do
    subject.role.should == :teaching_assistant


Besides this change, I hope this is becoming familiar to you. As the activity of forking, cloning, installing and running tests is very common and one you will likely continue to engage in throughout your development career.

  • Fork and clone this repository
  • Run Bundler
  • Run the tests / Setup Guard
  • Fix the failing tests
  • Save your changes
  • Share your changes

Choose Your Own Adventure

There is a fork in the road here. Here you are welcome to choose that path that you take (or perhaps take first). This next exercise you can choose to build a command-line driven quiz or create a simple website.

Choose something simple and obtainable within a short amount of time. I encourage you to find a partner for this exercise. The two of you ideally will quickly sketch out an idea and then code the exercise together.


Create a series of questions that:

  • Asks the user varying types of questions (yes/no,choices,input)
  • Store the result of each of these questions
  • At the end display the results back to the user

Your questions could take the form of a survey, setting up a dating profile, Ruby language test, walking through a fake configuration/installation etc.


  • Use the results that the user has given you to calculate a result
  • Answers that fork to a different question based on the previous response
  • Answer validation (for those open ended questions)
  • Use colors
Getting Started

We purposefully skipped some some introductory programming examples where we output questions and then ask for responses. Usually this is done through puts and gets. Next week we are going to explore some questions and answer type programming but with a much more robust way with Highline.

Run the command:

$ rake highline


$ ruby lib/highline.rb
NOTE: Window's users need to use a backslash \ instead of forward slashes /

It should hopefully say hello and ask you a question. When you are happy with that open up lib/highline.rb and look at the syntax. You may have a strange sense of deja-vu when looking at this code. It looks very much like RSpec, Guard, Rake, and all these other files that we have used up until this point.

Take a stab at adding your own questions, default answers, validations, or menus.


Create a web site:

  • Shows some information
  • Asks for some information from the user through a form
  • When they submit the form display the results back to the user

Your questions could take the form of a survey, setting up a profile/account, Ruby language test, fake user configuration screen.


  • Use view templates
  • Use a route pattern
  • Stylesheets and Javascript (if you are comfortable with them)
Getting Started

Sinatra is an awesome way to create websites in ruby very quickly and easily.

Run the command:

$ rake sinatra


$ ruby lib/sinatra.rb
NOTE: Window's users need to use a backslash \ instead of forward slashes /

It should launch a website on localhost:4567 that if you visit in your browser. When that is working for you open up lib/sinatra.rb and look at the syntax. Again you may have a strange sense of deja-vu when looking at the code.

Look at the documentation and create some of your own routes and play with parameters.

To exit the sinatra process in your terminal, use Ctrl-C.


There are tasks that you are likely finding yourself doing a lot. This week's exploration simply: Reflect on the way that you work and think about what you could do to make yourself more productive.

This is as always unique to your style, your tools, and your environment so there is no explicit goal in mind. The most important thing is to take the time to reflect and see what you can do to make changes.

Outlined below are a few areas that might give you some ideas where to start. I encourage you to not just look at your tools but also look at your life and identify some changes that may make an impact on how on how you work.

I encourage that after you find the area you want to change you make a small change or a few small changes. Try not send your whole process into upheaval. The name of the game is to make lasting changes through incremental improvements.


You may find yourself typing very similar commands that you wish you had shortcuts. Perhaps taking the time to set up a few git aliases would make your life easier.

Perhaps the command-line thing isn't your thing and you really wish you had a visual client. Perhaps a google search would lead you out of the darkness?


Syntax Highlighting

If you are still developing Ruby in black & white then it might be time to find a way to have your code appear in various colors. Syntax highlighting can often help your way around the code faster exposing issues when you forget to close a string, block or function.

Shortcut Keys

When you are looking for a particular line or searching for a particular word do you have to navigate through the menu? When you want to save or open a particular file do you have to navigate a lot of menus? All that time can be saved if you knew the short-cut keys for your editor (assuming, of course that they provide them for you).

Auto-Completion and Code Snippets

Several editors provide tools to help make you faster when you are typing the same things over and over again. Does your editor provide ways for you to easily re-use pieces of code.


Perhaps your editor has additional plugins that someone has already written that you could install to do some things easier.

Operating System

When you open up a terminal / command window are you in the right directory? Is it easy to open a file with your editor? Do you spend lots of time moving around windows, getting back to the work that you are doing? etc.

Something went wrong with that request. Please try again.