Try `100 + 32` in `irb`: Ruby evaluates the expression and prints `132`. The same language can run code saved in a plain-text file. Use `irb` for quick experiments and the `ruby` interpreter to run a program. section 1.1.1 section 1.1.6
Ruby programs manipulate objects. Assignment such as `x = 1` binds a local variable to an object; it does not make the variable the object. To ask an object to do something, send it a message with dot syntax. A method call without an explicit receiver goes to `self`, the default object in the current execution context. An object's class helps determine which methods it can respond to. section 1.1.2 section 1.5 section 2.1.1
A few small distinctions make Ruby experiments easier to read:
- `=` assigns; `==` compares and returns `true` or `false`. In a conditional, only `false` and `nil` count as false—not `0` or an empty string. section 1.1.2
- `puts` adds a newline when needed; `print` leaves the cursor where the output ends; `p` prints an inspection-oriented representation. section 1.1.2
- If `irb` waits after an incomplete expression, finish it on the same line or the next one. section 1.1.2
Check a file before running it
A Celsius-to-Fahrenheit program with a missing closing parenthesis cannot run: Ruby reports a syntax error, potentially at the end of the file after waiting for the expression to close. Run `ruby -cw c2f.rb` to check syntax and request warnings, then `ruby c2f.rb` to execute it. A wrong number in the conversion formula is different: it can produce a wrong answer even when the syntax is valid. section 1.1.6
The installation also includes tools around the language: `ri` and `rdoc` for documentation, `rake` for tasks, `gem` and Bundler utilities for packages, and `rdbg` for debugging. These complement the core syntax and the facilities for libraries and extensions. section 1.0 section 1.4
