1 Bootstrapping your Ruby literacy
The chapter introduces Ruby by giving readers a practical foundation for getting started quickly and comfortably. It emphasizes that Ruby is both a language and, lowercase ruby, the interpreter program that runs code. The opening approach is deliberately broad: learn enough syntax, tools, and workflow to begin writing, checking, and running simple programs while also gaining a sense of how Ruby is organized as a language and ecosystem.
A large part of the chapter is a survival kit for Ruby literacy. It reviews basic operations, input and output, conditionals, special values, comments, and the main kinds of identifiers such as variables, constants, keywords, and method names. It also explains Ruby’s object-based model, where messages are sent to objects through method calls, sometimes with a receiver and sometimes through the default object self. These ideas are reinforced through small temperature-conversion examples that show how to write a file, run it through the interpreter, check for syntax errors, use interactive testing, and handle keyboard and file input and output.
The later parts of the chapter expand beyond syntax into the practical environment around Ruby. Readers are shown how to inspect the Ruby installation, understand the locations of standard libraries, C extensions, site and vendor directories, and gems, and how Ruby loads libraries with load, require, and require_relative. The chapter then surveys the most useful built-in command-line tools, especially irb for experimentation, rake for tasks, gem and Bundler for package management, and rdbg for debugging. Overall, the chapter’s goal is to make readers self-sufficient enough to explore Ruby code, understand where it comes from, and begin using the language’s ecosystem productively.
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.
The Well-Grounded Rubyist, Fourth Edition ebook for free