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.
The Well-Grounded Rubyist, Fourth Edition ebook for free