You are previewing Metaprogramming Ruby 2.
O'Reilly logo
Metaprogramming Ruby 2

Book Description

Write powerful Ruby code that is easy to maintain and change. With metaprogramming, you can produce elegant, clean, and beautiful programs. Once the domain of expert Rubyists, metaprogramming is now accessible to programmers of all levels. This thoroughly revised and updated second edition of the bestselling Metaprogramming Ruby explains metaprogramming in a down-to-earth style and arms you with a practical toolbox that will help you write your best Ruby code ever.

Table of Contents

  1. Metaprogramming Ruby 2
    1. Copyright
    2. For the Best Reading Experience...
    3. Table of Contents
    4. What Readers Are Saying About Metaprogramming Ruby 2
    5. Foreword
    6. Acknowledgments
    7. Introduction
      1. About This Book
      2. About You
    8. Part 1: Metaprogramming Ruby
      1. Chapter 1: The M Word
        1. Ghost Towns and Marketplaces
        2. The Story of Bob, Metaprogrammer
        3. Metaprogramming and Ruby
      2. Chapter 2: Monday: The Object Model
        1. Open Classes
        2. Inside the Object Model
        3. Quiz: Missing Lines
        4. What Happens When You Call a Method?
        5. Quiz: Tangle of Modules
        6. Wrap-Up
      3. Chapter 3: Tuesday: Methods
        1. A Duplication Problem
        2. Dynamic Methods
        3. method_missing
        4. Quiz: Bug Hunt
        5. Blank Slates
        6. Wrap-Up
      4. Chapter 4: Wednesday: Blocks
        1. The Day of the Blocks
        2. Quiz: Ruby#
        3. Blocks Are Closures
        4. instance_eval()
        5. Callable Objects
        6. Writing a Domain-Specific Language
        7. Quiz: A Better DSL
        8. Wrap-Up
      5. Chapter 5: Thursday: Class Definitions
        1. Class Definitions Demystified
        2. Quiz: Class Taboo
        3. Singleton Methods
        4. Singleton Classes
        5. Quiz: Module Trouble
        6. Method Wrappers
        7. Quiz: Broken Math
        8. Wrap-Up
      6. Chapter 6: Friday: Code That Writes Code
        1. Coding Your Way to the Weekend
        2. Kernel#eval
        3. Quiz: Checked Attributes (Step 1)
        4. Quiz: Checked Attributes (Step 2)
        5. Quiz: Checked Attributes (Step 3)
        6. Quiz: Checked Attributes (Step 4)
        7. Hook Methods
        8. Quiz: Checked Attributes (Step 5)
        9. Wrap-Up
      7. Chapter 7: Epilogue
    9. Part 2: Metaprogramming in Rails
      1. Chapter 8: Preparing for a Rails Tour
        1. Ruby on Rails
        2. Installing Rails
        3. The Rails Source Code
      2. Chapter 9: The Design of Active Record
        1. A Short Active Record Example
        2. How Active Record Is Put Together
        3. A Lesson Learned
      3. Chapter 10: Active Support’s Concern Module
        1. Rails Before Concern
        2. ActiveSupport::Concern
        3. A Lesson Learned
      4. Chapter 11: The Rise and Fall of alias_method_chain
        1. The Rise of alias_method_chain
        2. The Fall of alias_method_chain
        3. A Lesson Learned
      5. Chapter 12: The Evolution of Attribute Methods
        1. Attribute Methods in Action
        2. A History of Complexity
        3. A Lesson Learned
      6. Chapter 13: One Final Lesson
        1. Metaprogramming Is Just Programming
    10. Part 3: Appendixes
      1. Appendix 1: Common Idioms
        1. Mimic Methods
        2. Nil Guards
        3. Self Yield
        4. Symbol#to_proc()
      2. Appendix 2: Domain-Specific Languages
        1. The Case for Domain-Specific Languages
        2. Internal and External DSLs
        3. DSLs and Metaprogramming
      3. Appendix 3: Spell Book
        1. The Spells
    11. You May Be Interested In…