Overview

1 Bootstrapping your Ruby literacy

This opening chapter aims to quickly ground you in Ruby so you can read, write, and run real code with confidence. It frames the Ruby ecosystem in three interlocking layers—the core language (syntax, semantics, and object model), the standard library and extensions (including how to add your own), and the command-line tools that ship with Ruby—and shows how they work together in practice. Along the way you learn how to get Ruby installed (often via a version manager), how to use the interactive console (irb) to explore ideas, and how to lean on the interpreter’s switches to check and run programs. The tone is hands-on and pragmatic: you get just enough of the big picture to navigate, plus concrete steps for building momentum quickly.

The chapter first equips you with a “syntax survival kit” and basic literacy around identifiers (local, instance, class, and global variables; constants; keywords; method names), then anchors everything in Ruby’s object-centric model: nearly everything is an object, and computation happens by sending messages (method calls) to receivers, sometimes with arguments and often with an implicit self. It clarifies the roles of objects and classes, including Ruby’s flexibility to change behavior at runtime. You immediately put this to use by writing and improving a small Celsius-to-Fahrenheit converter, learning the difference between puts and print, taking user input with gets and converting with to_i, and moving on to simple file I/O for reading and writing data. You also learn to lean on the interpreter for syntax checking and warnings, understand the load path, and split programs cleanly across files, contrasting load, require, and require_relative.

From there, the chapter surveys the Ruby installation and standard libraries (where code lives and how Ruby finds it), the role of gems, and the common tools you’ll use every day. You see how to query installation paths with RbConfig, what standard gems are bundled, and how to install and manage third-party packages with gem and Bundler. It then spotlights command-line switches (-c, -w, -e, -l, -r, -v, --version, -h), digs deeper into irb usage and prompts, and introduces rake for task automation and rdbg for interactive debugging. The net effect is a practical bootstrapping: you learn the language’s essentials, the mechanics of running and organizing code, and the toolchain that supports real-world Ruby development.

Summary

  • An overview of how Ruby works and what tools the Ruby programming environment provides
  • The difference between Ruby (the language) and ruby (the Ruby interpreter)
  • The typography of Ruby variables (all of which you’ll meet again and study in more depth)
  • Basic Ruby operators and built-in constructs
  • Writing, storing, and running a Ruby program file
  • Interactive Ruby sessions with irb
  • Keyboard input and screen output
  • Manipulating Ruby libraries with require and load
  • The anatomy of the Ruby installation
  • The command-line tools shipped with Ruby, including rake and gems

FAQ

What’s the difference between “Ruby”, “ruby”, and “RUBY”?Ruby is the programming language; ruby is the interpreter executable that runs your code; RUBY isn’t an acronym and shouldn’t be written in all caps.
What’s the easiest way to install Ruby on my system?- macOS/Linux: use a version manager such as rbenv, RVM, asdf, or chruby (all free).
- Windows: use RubyInstaller.
Version managers let you install and switch Ruby versions safely. The book references Ruby 3.4.5.
What is irb and how do I use it effectively?irb is the interactive Ruby console. Start it with irb (or irb --simple-prompt for cleaner prompts). Type Ruby expressions and see results immediately. Exit with exit or Ctrl-D. Multi-line prompts indicate an incomplete expression. Use --noecho to suppress value echoes.
How do I recognize common Ruby identifiers?- Local variables: first_name (lowercase/underscore/digits, not starting with a digit)
- Instance variables: @age
- Class variables: @@running_total
- Globals: $stdin, $:
- Constants: String, FIRST_NAME (start uppercase)
- Keywords: reserved words like def, class, if
- Method names: like locals and may end with ?, !, or =
What does “sending a message” mean vs “calling a method”?Ruby treats values as objects. receiver.message(args) “sends a message” to the receiver; the object then runs the corresponding method. If no method exists, Ruby can intercept via method_missing. Bareword calls like puts "Hi" are sent to the default receiver self.
How do I write, check, and run my first Ruby program?1) Save code in .rb (e.g., c2f.rb).
2) Syntax-check without running: ruby -cw c2f.rb → “Syntax OK”.
3) Run: ruby c2f.rb.
Tip: puts adds a newline; print does not; p shows an object’s inspect string.
How do I read input and work with files?- Keyboard: val = gets (use to_i/to_f to convert).
- Read file: num = File.read("temp.dat").
- Write file: fh = File.new("temp.out","w"); fh.puts value; fh.close.
What’s the difference between load, require, and require_relative?- load "file.rb": executes the file every time you call it; usually needs full filename; searches current dir (special case) and load path.
- require "feature": loads a feature once (no duplicate loads), extensionless; works for Ruby (.rb) and compiled extensions.
- require_relative "path/to/feature": resolves relative to the requiring file’s directory.
- Load path: inspect with $:; installation paths via RbConfig::CONFIG.
Where does Ruby keep its libraries and gems?- Standard library (Ruby files): RbConfig::CONFIG["rubylibdir"]
- Compiled extensions: RbConfig::CONFIG["archdir"]
- Site/vendor libraries: sitedir, vendordir (and their subdirs)
- Gems: installed under the gems directory; manage with gem and Bundler; after require "gemname", its path appears in $:.
Which built-in tools and command-line switches should I know?- Tools: ruby (interpreter), irb (REPL), rdoc/ri (docs), rake (tasks), gem/bundle (packages), rdbg (debugger).
- Useful switches: -c (check syntax), -w (warnings), -e (run inline code), -l (line mode), -r name (require feature), -v (version + verbose), --version (version only), -h (help).

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
$399.99
only $33.33 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
$399.99
only $33.33 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