1 Bootstrapping your Ruby literacy
This chapter launches the reader’s Ruby journey by bootstrapping practical literacy in the language. It frames Ruby as an ecosystem with three interlocking layers—core language concepts, extensions and libraries, and command-line tools—and sets the goal of giving you enough syntax, workflow, and mental models to write, run, and reason about programs with confidence. Along the way it emphasizes Ruby’s design philosophy and developer ergonomics, encouraging rapid experimentation (especially with the interactive console) and a clear understanding of how the interpreter and tools fit together.
You begin with a concise “syntax survival kit” and identifier literacy (local, instance, class, and global variables; constants; keywords; method names), then move to Ruby’s object model: everything is an object that responds to messages, method calls use the dot (or bareword form on the default receiver, self), arguments are objects, and dynamic techniques like method_missing exist. The chapter walks through writing, checking, and running small programs—a Celsius-to-Fahrenheit converter evolves from hardcoded output to keyboard input and file I/O—while illustrating key idioms such as puts vs print, converting input (to_i), handling multi-line expressions in the console, and catching syntax issues with interpreter flags. It also explains loading code across files with load, require, and require_relative, and how Ruby’s load path determines where features are found.
Next, you tour the Ruby installation: where standard libraries live, how compiled C extensions are organized, and where site/vendor code and gems are stored, with rbconfig as your guide. The tooling overview covers everyday interpreter switches (-c, -w, -e, -l, -r, -v, and friends), effective use of irb (simple prompts, echo control, interruption), task automation with rake (namespaces, tasks), package management with RubyGems and Bundler (declaring and installing dependencies), and interactive debugging with rdbg (breakpoints, stepping, inspecting state). The result is a practical foundation—language basics, file and console workflows, extension mechanics, and tool fluency—that prepares you for deeper Ruby concepts in the rest of the book.
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