Recap Exercise

In case you get stuck anywhere, don't be afraid to ask the coaches! They are here to help and will gladly explain everything to you!

Take notes during the exercises. Even if you never look at them again, they will help you memorise things!

For these exercises, you will use your editor (Visual Studio Code or similar).

First, create an empty file with a meaningful name for this exercise, for example number_input.rb. Note the file extension .rb! Also remember what folder you saved your file in. It makes sense to create a folder for each lesson of the course.

Then, use cd in the command line to change to that folder. When you run ls you should see your file there.

Now you can run your Ruby program with ruby number_input.rb in the command line.

Repeat the above steps and remember to save your file in the editor before running it!

Write a method called get_user_number_input. When you call the method, it should ask the user for a number with a nice text. The method should then return this number as an Integer, not a String.

Here’s something to get you started:

def get_user_number_input
  # your code goes here
end

number = get_user_number_input
puts "The user entered the number #{number} and it's a #{number.class}"

When you execute it, you should get:

Example interaction (user entered text is bold):

> ruby number_input.rb
Hi, please enter a number: 42
The user entered the number 42 and it's a Integer