Your First Program

Ready to write your first Ruby program? In the Repl.it file below (the white top section), you'll see we've written the code puts "Hello, world". Type puts "Hello, world" for yourself in the Repl.it shell (the dark blue bottom section) and press enter.

If Hello, world! printed in your shell, then congratulations: you're already a programmer! Now let's think like a programmer by investigating this code's components and how they cooperate to make a program. A program is a sequence of instructions that a computer executes to perform a specific task ( in this case, printing Hello, world).

Note: Throughout this curriculum, please experiment with the code in the examples and type and run your own code in the shell (the dark blue bottom section) to practice and test your understanding of Ruby.

puts "Hello, world!"

You've learned that the quotation marks enclosing "Hello, world!" denote a string; however, you haven't learn what puts means. puts is not a number, string, boolean or nil.

puts is not an object at all. Instead, puts is a method. We'll cover methods more thoroughly in later chapters, but for now think of methods as performing an action on an object. puts performs the action of printing the string "Hello, world".

You can use puts with an object of any data type. Try running these in the shell:

puts nil prints nothing. Can you think of why?

You've already run five programs! Time for your first bug.

results matching ""

    No results matching ""