Ruby is a powerful programming language with a focus on simplicity, but beneath its elegant syntax it performs countless unseen tasks.
Ruby Under a Microscope gives you a hands-on look at Ruby's core, using extensive diagrams and thorough explanations to show you how Ruby is implemented (no C skills required). Author Pat Shaughnessy takes a scientific approach, laying out a series of experiments with Ruby code to take you behind the scenes of how programming languages work. You'll even find information on JRuby and Rubinius (two alternative implementations of Ruby), as well as in-depth explorations of Ruby's garbage collection algorithm.
Ruby Under a Microscope will teach you:
How a few computer science concepts underpin Ruby's complex implementation
How Ruby executes your code using a virtual machine
How classes and modules are the same inside Ruby
How Ruby employs algorithms originally developed for Lisp
How Ruby uses grammar rules to parse and understand your code
How your Ruby code is translated into a different language by a compiler
No programming language needs to be a black box. Whether you're already intrigued by language implementation or just want to dig deeper into Ruby, you'll find Ruby Under a Microscope a fascinating way to become a better programmer.
Covers Ruby 2.x, 1.9 and 1.8
Chapter 1 Tokenization and Parsing
Tokens: The Words That Make Up the Ruby Language
Experiment 1-1: Using Ripper to Tokenize Different Ruby Scripts
Parsing: How Ruby Understands Your Code
Experiment 1-2: Using Ripper to Parse Different Ruby Scripts
Chapter 2 Compilation
No Compiler for Ruby 1.8
Ruby 1.9 and 2.0 Introduce a Compiler
How Ruby Compiles a Simple Script
Compiling a Call to a Block
Experiment 2-1: Displaying YARV Instructions
The Local Table
Experiment 2-2: Displaying the Local Table
Chapter 3 How Ruby Executes Your Code
YARV’s Internal Stack and Your Ruby Stack
Experiment 3-1: Benchmarking Ruby 2.0 and Ruby 1.9 vs. Ruby 1.8
Local and Dynamic Access of Ruby Variables
Experiment 3-2: Exploring Special Variables
Chapter 4 Control Structures and Method Dispatch
How Ruby Executes an if Statement
Jumping from One Scope to Another
Experiment 4-1: Testing How Ruby Implements for Loops Internally
The send Instruction: Ruby’s Most Complex Control Structure
Calling Normal Ruby Methods
Calling Built-In Ruby Methods
Experiment 4-2: Exploring How Ruby Implements Keyword Arguments
Chapter 5 Objects and Classes
Inside a Ruby Object
Experiment 5-1: How Long Does It Take to Save a New Instance Variable?
What’s Inside the RClass Structure?
Experiment 5-2: Where Does Ruby Save Class Methods?
Chapter 6 Method Lookup and Constant Lookup
How Ruby Implements Modules
Ruby’s Method Lookup Algorithm
Experiment 6-1: Modifying a Module After Including It
Lexical Scope in Ruby
Experiment 6-2: Which Constant Will Ruby Find First?
Chapter 7 The Hash Table: The Workhorse of Ruby Internals
Hash Tables in Ruby
Experiment 7-1: Retrieving a Value from Hashes of Varying Sizes
How Hash Tables Expand to Accommodate More Values
Experiment 7-2: Inserting One New Element into Hashes of Varying Sizes
How Ruby Implements Hash Functions
Experiment 7-3: Using Objects as Keys in a Hash
Chapter 8 How Ruby Borrowed a Decades-Old Idea from Lisp
Blocks: Closures in Ruby
Experiment 8-1: Which Is Faster: A while Loop or Passing a Block to each?
Lambdas and Procs: Treating a Function as a First-Class Citizen
Experiment 8-2: Changing Local Variables After Calling lambda
Chapter 9 Metaprogramming
Alternative Ways to Define Methods
Experiment 9-1: Who Am I? How self Changes with Lexical Scope
Metaprogramming and Closures: eval, instance_eval, and binding
Experiment 9-2: Using a Closure to Define a Method
Experiment 11-1: Comparing Backtraces in MRI and Rubinius
Arrays in Rubinius and MRI
Experiment 11-2: Exploring the Rubinius Implementation of Array#shift
Chapter 12 Garbage Collection in MRI, JRuby, and Rubinius
Garbage Collectors Solve Three Problems
Garbage Collection in MRI: Mark and Sweep
Experiment 12-1: Seeing MRI Garbage Collection in Action
Garbage Collection in JRuby and Rubinius
Copying Garbage Collection
Generational Garbage Collection
Concurrent Garbage Collection
Experiment 12-2: Using Verbose GC Mode in JRuby
Ruby Under a Microscope
No Starch Press
Safari Books Online
| ISBN 10:
| ISBN 10:
Well known for his coding expertise and passion for the Ruby programming language, Pat Shaughnessy blogs and writes tutorials at http://patshaughnessy.net/. He also develops Ruby applications at management consulting firm McKinsey & Co. Shaughnessy is a regular presenter on the Ruby conference circuit, and his articles and presentations have been featured in the Ruby Weekly newsletter, the Ruby5 podcast, and The Ruby Show.
Great ressource if you are interrested in how a language like Ruby is really implemented. This book is best suited for the curious and those who want to get a grip on how things really work, not those who want to learn a better way to use Ruby.
The book starts with details on how MRI parse and compile your script to a internal representation, making it a great concrete application of various compiler techniques. They are presented in a clear and concrete way that is sometime missing from the classic books on compilers.
The middle of the book deals mainly with the MRI run time and how it keeps track of your data and where you are in your program. The various illustration are really clear and you can really understand what's going on. I had various 'ha ha !' moments where I finaly understood various limitations or behaviors of the language.
The end of the book deals with garbage collection and makes comparaisons with other runtimes like the JVM or Rubinius. While the comparaisions are pretty interresting, they may or may not be your prime issue, depending on how you use Ruby. If you are only using Ruby for small to medium scripts like me, it's not a real big deal.
I'm not sure reading this book is a must read for Rubists. For diving into Ruby, you should really start with the seminal 'The Ruby Programming Language' or 'Ruby cookbook' (even if the cookbook is now getting a little bit old, it remains largely valid).
Bottom Line Yes, I would recommend this to a friend