Introduction to Ruby

Learn about Ruby, an object-oriented scripting language you can use on its own or as part of the Ruby on Rails web framework.

Start[missing "en.views.course_landing_page.learn-ruby.course_illustration" translation]
Chevron Left Icon
Introduction to Ruby
Lesson 1 of 2
Chevron Right Icon
  1. 1

    Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is: *Hi...

  2. 2

    In Ruby, your information (or data) can come in different types. There are three data types in Ruby that we're interested in right now: numbers, booleans (which can be true or false), a...

  3. 3

    One of the most basic concepts in computer programming is the variable. You can think of a variable as a word or name that grasps a single value. For example, let's say you needed the number 25...

  4. 4

    Ruby isn't limited to simple expressions of assignment like [...] ; it can also do all the math you learned about in school. There are six arithmetic operators we're going to focus on: Addition ...

  5. 5

    The [...] command just takes whatever you give it and prints it to the screen. [...] (for "put string") is slightly different: it adds a new (blank) line after the thing you want it to print. Y...

  6. 6

    Because everything in Ruby is an object (more on this later), everything in Ruby has certain built-in abilities called methods. You can think of methods as "skills" that certain objects have. F...

  7. 7

    Methods are summoned using a [...] . If you have a string, [...] , and take the [...] of it, Ruby will return the length of the string (that is, the number of characters—letters, numbers, space...

  8. 8

    The [...] method is called the same way [...] is, but instead of asking Ruby to tell you how long a string is, it spits out a backwards version of the string you gave it. For instance, [...] ...

  9. 9

    Let's try one more method (er, two methods). As you might have guessed, the [...] and [...] methods convert a string to ALL UPPER CASE or all lower case, respectively.

  10. 10

    You probably saw us use the [...] sign a few times in earlier exercises. The [...] sign is for comments in Ruby. A comment is a bit of text that Ruby won't try to run as code: it's just for...

  11. 11

    You can write a comment that spans multiple lines by starting each line with a [...] , but there's an easier way. If you start with [...] and end with [...] , everything between those two exp...

  12. 12

    There are many different kinds of variables you'll encounter as you progress through these courses, but right now we're just concerned with regular old local variables. By convention, these var...

  13. 13

    Let's quickly review how to declare and set variables. Remember, you declare a variable just by saying its name, and you set it using [...] . You can always check the Hint below if you need mo...

  14. 14

    Good! Now let's do a little math.

  15. 15

    Well done! Let's do a little review of string methods. Remember, you call a method by using the [...] operator, like this: [...] .

  16. 16

    Great work! For our last review exercise for this lesson, let's go over single- and multi-line comments.

  1. 1

    This project will help you create a small program that will read a user's input and correct his or her capitalization. Users can provide an almost infinite range of input, so it makes our lives eas...

  2. 2

    First, let's write the code we're already familiar with. In order to get input from the user, we'll first need to [...] a prompt on the screen.

  3. 3

    Good! Now let's try something new. You may have noticed this weird little line of code repeated in our example: [...] [...] is the Ruby method that gets input from the user. When getting inpu...

  4. 4

    All right! Now we need to repeat what we've done for [...] , [...] , and [...] .

  5. 5

    As you might have noticed, Ruby's not really returning any feedback to us. We want to be able to see our string formatting in action! For this, we'll need one more new piece of syntax. If you defi...

  6. 6

    Great! Now we've got our output, but as you can see, we haven't used string methods to properly capitalize everything yet. [...] 1. First we introduce one new method, [...] , here. It capitali...

  7. 7

    Perfect! In just a few short steps, you've created your own Ruby program with real-world applications. Feel free to add to your program or change it as much as you like.

Introduction to Ruby

Start[missing "en.views.course_landing_page.learn-ruby.course_illustration" translation]