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.

Publisher resources

View/Submit Errata

Table of contents

  1.  Foreword
  2.  Acknowledgments
  3.  Introduction
    1. About This Book
    2. About You
  4. Part I. Metaprogramming Ruby
    1. 1. The M Word
      1. Ghost Towns and Marketplaces
      2. The Story of Bob, Metaprogrammer
      3. Metaprogramming and Ruby
    2. 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. 3. Tuesday: Methods
      1. A Duplication Problem
      2. Dynamic Methods
      3. method_missing
      4. Quiz: Bug Hunt
      5. Blank Slates
      6. Wrap-Up
    4. 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. 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. 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. 7. Epilogue
  5. Part II. Metaprogramming in Rails
    1. 8. Preparing for a Rails Tour
      1. Ruby on Rails
      2. Installing Rails
      3. The Rails Source Code
    2. 9. The Design of Active Record
      1. A Short Active Record Example
      2. How Active Record Is Put Together
      3. A Lesson Learned
    3. 10. Active Support’s Concern ModuleActive Support’s Concern Module
      1. Rails Before Concern
      2. ActiveSupport::Concern
      3. A Lesson Learned
    4. 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. 12. The Evolution of Attribute Methods
      1. Attribute Methods in Action
      2. A History of Complexity
      3. A Lesson Learned
    6. 13. One Final Lesson
      1. Metaprogramming Is Just Programming
  6. Part III. Appendixes
    1. A1. Common Idioms
      1. Mimic Methods
      2. Nil Guards
      3. Self Yield
      4. Symbol#to_proc()
    2. A2. Domain-Specific Languages
      1. The Case for Domain-Specific Languages
      2. Internal and External DSLs
      3. DSLs and Metaprogramming
    3. A3. Spell Book
      1. The Spells

Product information

  • Title: Metaprogramming Ruby 2
  • Author(s): Paolo Perrotta
  • Release date: August 2014
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781941222126