Programming Ruby 3.3 (5th Edition)
The Pragmatic Programmers' Guide
by Noel Rappin, with Dave Thomas
Ruby is one of the most important programming languages in use for web
development. It powers the Rails framework, which is the backing of some
of the most important sites on the web. The Pickaxe Book, named for the
tool on the cover, is the definitive reference on Ruby, a
highly-regarded, fully object-oriented programming language. This
updated edition is a comprehensive reference on the language itself,
with a tutorial on the most important features of Ruby—including
pattern matching and Ractors—and describes the language through Ruby
3.3.
Would you like to go from first idea to working code much, much faster?
Do you currently spend more time satisfying the compiler instead of your
clients or end users? Are you frustrated with demanding languages that
seem to get in your way instead of helping you get the work done? Are
you using Rails and want to dig deeper into the underlying Ruby
language? If so, then we’ve got a language and book for you!
Ruby is a fully object-oriented language. The combination of the power
of a pure object-oriented language with the convenience of a scripting
language makes Ruby a favorite tool of programmers that want to get
things done quickly and cleanly.
This comprehensive reference manual for Ruby includes a description of
the most important standard library modules, built-in classes, and
modules. It also includes all the new and changed syntax and semantics
introduced through Ruby 3.3, including pattern matching and Ractors, and
describes the language through Ruby 3.3.
What You Need
- This book assumes you have a basic understanding of object-oriented
programming.
- In general, Ruby programmers tend to favor the the command line for
running their code, and they tend to use text editors rather than
IDEs.
- Ruby runs on Windows, Linux, and MacOS.
Resources
Releases:
- P1.0 2024/01/09
- B7.0 2023/12/06
- B6.0 2023/11/14
- B5.0 2023/07/28
- Facets of Ruby
- Getting Started
- Installing Ruby
- Installing Ruby for Windows
- Running Ruby
- Creating Ruby Programs
- Getting More Information about Ruby
- What’s Next
- Ruby.new
excerpt
- Ruby Is an Object-Oriented Language
- Some Basic Ruby
- Arrays and Hashes
- Symbols
- Control Structures
- Regular Expressions
- Blocks
- Reading and ‘Riting
- Command-Line Arguments
- Commenting Ruby
- What’s Next
- Classes, Objects, and Variables
- Defining Classes
- Objects and Attributes
- Classes Working with Other Classes
- Specifying Access Control
- Variables
- Reopening Classes
- What’s Next
- Collections, Blocks, and Iterators
- Arrays
- Hashes
- Digging
- Word Frequency: Using Hashes and Arrays
- Blocks and Enumeration
- What’s Next
- More about Methods
- Defining a Method
- Calling a Method
- What’s Next
- Sharing Functionality: Inheritance, Modules, and Mixins
excerpt
- Inheritance and Messages
- Modules
- Inheritance, Mixins, and Design
- What’s Next
- Basic Types: Numbers, Strings, and Ranges
- Numbers
- Strings
- Ranges
- What’s Next
- Regular Expressions
- What Regular Expressions Let You Do
- Creating and Using Regular Expressions
- Regular Expression Patterns
- Regular Expression Syntax
- What’s Next
- Expressions
- Operator Expressions
- Command Expressions
- Assignment
- Conditional Execution
- Loops and Iterators
- Pattern Matching
- What’s Next
- Exceptions
- The Exception Class
- Handling Exceptions
- Raising Exceptions
- Using Catch and Throw
- What’s Next
- Basic Input and Output
- What Is an I/O Object?
- Opening and Closing Files
- Reading and Writing Files
- Talking to Networks
- What’s Next
- Threads, Fibers, and Ractors
- Multithreading with Threads
- Running Multiple External Processes
- Creating Fibers
- Understanding Ractors
- What’s Next
- Testing Ruby Code
- Why Unit Test?
- Testing with Minitest
- Structuring Tests
- Creating Mock Objects in Minitest
- Organizing and Running Tests
- Testing with RSpec
- What’s Next
- Ruby in Its Setting
- Ruby from the Command Line
excerpt
- Calling the Ruby Command
- Ruby Command-Line Options
- Making Your Code an Executable Program
- Processing Command-Line Arguments to Your Code
- Accessing Environment Variables
- Where Ruby Finds Its Libraries
- Using the Rake Build Tool
- The Build Environment
- What’s Next
- Ruby Gems
- Installing and Managing Gems
- Using Bundler to Manage Groups of Gems
- Writing and Packaging Your Own Code into Gems
- Organizing Your Source Code
- Distributing and Installing Your Code
- What’s Next
- Interactive Ruby
- Using irb
- Navigating irb
- Configuring irb
- What’s Next
- Debugging Ruby
- Printing Things
- The Ruby Debugger
- Pry
- Debugging Performance Issues with Benchmark
- What’s Next
- Typed Ruby
excerpt
- What’s a Type?
- Official Ruby Typing with RBS
- Ruby Typing with Sorbet
- What’s Next
- Documenting Ruby
- Documenting with RDoc
- Adding RDoc to Ruby Code
- Running RDoc
- Documenting with YARD
- What’s Next
- Ruby Crystallized
- Ruby and the Web
- Ruby’s Web Utilities
- Templating with ERB
- Serving Ruby Code to the Web
- Ruby in the Browser with Web Assembly
- What’s Next
- Ruby Style
- Written Ruby Style
- Using RuboCop
- Using Standard
- Ruby Style in the Large
- Duck Typing
- What’s Next
- The Ruby Object Model and Metaprogramming
- Understanding Objects and Classes
- Defining Singleton Methods
- Inheritance and Visibility
- Modules and Mixins
- Metaprogramming Class-Level Macros
- Using instance_eval and class_eval
- Using Hook Methods
- A Metaprogramming Example
- Top-Level Execution Environment
- What’s Next
- Reflection and Object Space
- Looking at Objects
- Looking at Classes
- Calling Methods Dynamically
- System Hooks
- Tracing Your Program’s Execution
- Behind the Curtain: The Ruby VM
- Marshaling and Distributed Ruby
- What’s Next
- Ruby Language Reference
- Language Reference: Literal Types and Expressions
- Source Layout
- Ruby Literals
- Regular Expressions
- Names
- Values, Variables, and Constants
- Expressions, Conditionals, and Loops
- Language Reference: Objects and Classes
- Method Definition
- Invoking a Method
- Aliasing
- Defining Classes
- Defining Modules
- Access Control
- Blocks, Closures, and Proc Objects
- Exceptions
- Catch and Throw
- Typed Ruby
- Ruby Library Reference
- Library Reference: Core Data Types
- Dates and Times
- Math
- Numbers
- Random and SecureRandom
- Regexp
- Strings
- Symbols
- Library Reference: Ruby’s Object Model
- BasicObject
- Class
- Comparable
- Kernel
- Method
- Module
- Object
- Library Reference: Enumerators and Containers
- Array
- Enumerable
- Enumerator
- Hash
- Set
- Library Reference: Input, Output, Files, and Formats
- CSV
- Dir
- File
- FileUtils
- IO
- JSON
- Pathname
- StringIO
- Tempfile
- URI
- YAML
- Library Reference: Ruby on Ruby
- Benchmark
- Data
- Delegator and SimpleDelegator
- Logger
- ObjectSpace
- Observable
- OpenStruct
- PP
- Prism
- Ripper
- Singleton
- Struct
- Unbound Method
- Appendixes
- Troubleshooting Ruby
- Common Issues
- Debugging Tips
- I Can’t Look It Up!
- Command-Line Basics
- The Command Prompt
- Folders, Directories, and Navigation
- Ruby Runtimes
- Just-in-Time Compilers
- TruffleRuby
- JRuby
- mRuby
- Other Runtimes
- Ruby Changes
- Version 2.0
- Version 2.1
- Version 2.2
- Version 2.3
- Version 2.4
- Version 2.5
- Version 2.6
- Version 2.7
- Version 3.0
- Version 3.1
- Version 3.2
- Version 3.3
Author
Noel Rappin is a Staff Software Engineer at Chime Financial. He is
the author of multiple technical books including Rails 5 Test
Prescriptions and Modern Front End Development With Rails, and was the
host of the Tech Done Right Podcast. Follow Noel on Twitter
@noelrap, and online at
noelrappin.com.
Dave Thomas is a cornerstone of the Ruby community, and is
personally responsible for many of its innovative directions and
initiatives. He is one of the founders of the Pragmatic Programmers and
the Pragmatic Bookshelf.