Overview

1 Bootstrapping your Ruby literacy

This chapter introduces Ruby by giving you just enough practical knowledge to start experimenting confidently. It emphasizes that Ruby is not only a language but also an ecosystem of tools, files, libraries, and conventions that work together. The chapter’s purpose is to help you bootstrap your Ruby literacy so you can begin reading, writing, running, and debugging programs while developing an intuition for how Ruby thinks about code.

To get started, the chapter walks through basic syntax, common identifiers, and the object-and-message model at the heart of Ruby. You learn how to recognize variables, constants, keywords, and method names, along with the roles of objects, classes, and methods. The chapter uses simple examples like a Celsius-to-Fahrenheit converter to demonstrate arithmetic, assignment, output, keyboard input, file input, file output, and the difference between syntax errors and ordinary logic mistakes. It also highlights practical habits such as using a text editor, testing snippets in interactive mode, and reading error messages and tracebacks as part of everyday Ruby work.

The chapter also broadens the view beyond the core language to include the Ruby installation, standard libraries, extensions, gems, and bundled command-line tools. You see how to inspect Ruby’s installation paths, how load, require, and require_relative bring in code, and how gems are installed and managed with RubyGems and Bundler. Finally, the chapter surveys important tools such as ruby, irb, rake, and rdbg, showing how they support development, task automation, experimentation, and debugging. Overall, it presents Ruby as a practical, flexible system where learning the language means learning how its pieces fit together in real use.

Summary

  • irb allows you to evaluate expressions and print results. We’ll use it extensively throughout the book.
  • Ruby allows us to easily perform arithmetic, assignment, and determine equality.
  • print, puts, p, and gets are methods used for basic I/O.
  • Local variables (first_name), instance variables (@first_name), class variables (@@first_name), and global variables ($first_name) are distinguished by the character(s) that precede them. Constants start with uppercase letters and Pascal case (FirstName) or all uppercase separate by underscores (FIRST_NAME).
  • Everything in Ruby is an object. We send messages to objects by using the . syntax. Bareword calls send to self, and unknown messages are handled via method_missing.
  • ri/rdoc, rake, gem, bundle, and rdbg are all useful command line tools that come pre-packaged with Ruby. Spend some time getting to know these tools and what they can do.

FAQ

What is the difference between Ruby and ruby?Ruby is the programming language, while ruby is the executable program that reads and runs Ruby code.
What are the three main levels of the Ruby landscape covered in this chapter?The chapter organizes Ruby into three levels: the core language, extensions and libraries that ship with Ruby, and command-line tools that come with Ruby.
Why is irb so useful for learning Ruby?irb is an interactive Ruby console that lets you type code, immediately execute it, and see the resulting value. It is especially helpful for experimenting with syntax and testing small snippets quickly.
How do you exit an irb session?You can normally exit irb by typing exit. On many systems, Ctrl-D also works.
What do puts and print do differently?puts prints its output and adds a newline if needed, while print outputs text without automatically moving to the next line.
What are false, nil, and true used for in conditionals?false and nil are the only values that evaluate as false in a conditional. Everything else, including true, 0, and empty strings, evaluates as true.
What is the difference between load and require?load reads and executes a file every time it is called, while require loads a feature only once and is the usual way to bring in libraries and extensions.
What does require_relative do?require_relative loads a file by searching relative to the directory containing the current file, which makes it convenient for local project file structures.
How do you check a Ruby file for syntax errors without running it?Use the Ruby interpreter with the -c switch, often combined with -w for warnings, such as ruby -cw filename.rb.
What is the purpose of rake in Ruby?rake is a Ruby-based task-management utility used to define and run tasks from a Rakefile, similar in spirit to make.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Well-Grounded Rubyist, Fourth Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Well-Grounded Rubyist, Fourth Edition ebook for free