معرفی کتاب «Metaprogramming Ruby : program like the Ruby pros» نوشتهٔ Paolo Perrotta; Paolo Perrotta، منتشرشده توسط نشر Pragmatic Bookshelf در سال 2010. این کتاب در 20 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Metaprogramming Ruby : program like the Ruby pros» در دستهٔ بدون دستهبندی قرار دارد.
Everyone in the Ruby world seems to be talking about metaprogramming--how you can use it to remove duplication in your code and write elegant, beautiful programs. Now you can get in on the action as well. This book describes metaprogramming as an essential component of Ruby. Once you understand the principles of Ruby, including the object model, scopes, and eigenclasses, you're on your way to applying metaprogramming both in your daily work and in your fun, after-hours projects. Learning metaprogramming doesn't have to be difficult or boring. By taking you on a Monday-through-Friday workweek adventure with a pair of programmers, Paolo Perrotta helps make mastering the art of metaprogramming both straightforward and entertaining. The book is packed with: Pragmatic examples of metaprogramming in action, many of which come straight from popular libraries or frameworks, such as Rails. Programming challenges that let you experiment and play with some of the most fun, "out-there" metaprogramming concepts. Metaprogramming __spells__--34 practical recipes and idioms that you can study and apply right now, to write code that is sure to impress. Whether you're a Ruby apprentice on the path to mastering the language or a Ruby wiz in search of new tips, this book is for you. Contents......Page 7 Foreword......Page 10 Dynamic Attributes......Page 0 Introduction......Page 13 The ``M'' Word......Page 14 About This Book......Page 21 About You......Page 24 Metaprogramming Ruby......Page 26 Monday with Bill......Page 27 Open Classes......Page 28 The Truth About Classes......Page 33 Quiz: Missing Lines......Page 45 What Happens When You Call a Method?......Page 46 Quiz: Tangle of Modules......Page 56 Object Model Wrap-Up......Page 59 Tuesday: Methods......Page 60 A Duplication Problem......Page 61 Dynamic Methods......Page 63 method_missing()......Page 71 Quiz: Bug Hunt......Page 82 More method_missing()......Page 84 Wednesday: Blocks......Page 91 How to Handle Hump Day......Page 92 Quiz: Ruby#......Page 93 Closures......Page 96 instance_eval()......Page 105 Callable Objects......Page 108 Writing a Domain-Specific Language......Page 116 Quiz: A Better DSL......Page 118 Class Definitions Demystified......Page 123 Quiz: Class Taboo......Page 130 Singleton Methods......Page 132 Eigenclasses......Page 137 Quiz: Module Trouble......Page 150 Aliases......Page 152 Quiz: Broken Math......Page 157 Leading the Way......Page 160 Kernel#eval......Page 163 Quiz: Checked Attributes (Step 1)......Page 173 Quiz: Checked Attributes (Step 2)......Page 176 Quiz: Checked Attributes (Step 3)......Page 178 Quiz: Checked Attributes (Step 4)......Page 179 Hook Methods......Page 180 Quiz: Checked Attributes (Step 5)......Page 186 Epilogue......Page 188 Metaprogramming in Rails......Page 189 The Design of ActiveRecord......Page 190 Preparing for the Tour......Page 191 The Design of ActiveRecord......Page 193 Lessons Learned......Page 202 Inside ActiveRecord......Page 206 Dynamic Finders......Page 214 Lessons Learned......Page 219 Testing Metaprogramming......Page 224 Defusing Monkeypatches......Page 232 Lessons Learned......Page 237 Appendixes......Page 239 Mimic Methods......Page 240 Nil Guards......Page 243 Tricks with Method Arguments......Page 244 Self Yield......Page 248 Symbol#to_proc()......Page 249 The Case for Domain-Specific Languages......Page 252 Internal and External DSLs......Page 254 DSLs and Metaprogramming......Page 255 The Spells......Page 256 Bibliography......Page 268 B......Page 269 C......Page 270 E......Page 271 I......Page 272 M......Page 273 O......Page 274 S......Page 275 V......Page 276 Y......Page 277 Contents 7 Foreword 10 Acknowledgments -1 Introduction 13 The ``M'' Word 14 About This Book 21 About You 24 Metaprogramming Ruby 26 Monday: The Object Model 27 Monday with Bill 27 Open Classes 28 The Truth About Classes 33 Quiz: Missing Lines 45 What Happens When You Call a Method? 46 Quiz: Tangle of Modules 56 Object Model Wrap-Up 59 Tuesday: Methods 60 A Duplication Problem 61 Dynamic Methods 63 method_missing() 71 Quiz: Bug Hunt 82 More method_missing() 84 Wednesday: Blocks 91 How to Handle Hump Day 92 Quiz: Ruby# 93 Closures 96 instance_eval() 105 Callable Objects 108 Writing a Domain-Specific Language 116 Quiz: A Better DSL 118 Thursday: Class Definitions -1 Class Definitions Demystified 123 Quiz: Class Taboo 130 Singleton Methods 132 Eigenclasses 137 Quiz: Module Trouble 150 Aliases 152 Quiz: Broken Math 157 Friday: Code That Writes Code 160 Leading the Way 160 Kernel#eval 163 Quiz: Checked Attributes (Step 1) 173 Quiz: Checked Attributes (Step 2) 176 Quiz: Checked Attributes (Step 3) 178 Quiz: Checked Attributes (Step 4) 179 Hook Methods 180 Quiz: Checked Attributes (Step 5) 186 Epilogue 188 Metaprogramming in Rails 189 The Design of ActiveRecord 190 Preparing for the Tour 191 The Design of ActiveRecord 193 Lessons Learned 202 Inside ActiveRecord 206 Dynamic Attributes -1 Dynamic Finders 214 Lessons Learned 219 Metaprogramming Safely 224 Testing Metaprogramming 224 Defusing Monkeypatches 232 Lessons Learned 237 Appendixes 239 Common Idioms 240 Mimic Methods 240 Nil Guards 243 Tricks with Method Arguments 244 Self Yield 248 Symbol#to_proc() 249 Domain-Specific Languages 252 The Case for Domain-Specific Languages 252 Internal and External DSLs 254 DSLs and Metaprogramming 255 Spell Book 256 The Spells 256 Bibliography 268 Index 269 Symbols 269 A 269 B 269 C 270 D 271 E 271 F 272 G 272 H 272 I 272 J 273 K 273 L 273 M 273 N 274 O 274 P 275 Q 275 R 275 S 275 T 276 U 276 V 276 W 277 Y 277
Everyone in the Ruby world seems to be talking about metaprogramming—how you can use it to remove duplication in your code and write elegant, beautiful programs. Now you can get in on the action as well.
This book describes metaprogramming as an essential component of Ruby. Once you understand the principles of Ruby, including the object model, scopes, and eigenclasses, you're on your way to applying metaprogramming both in your daily work and in your fun, after-hours projects.
Learning metaprogramming doesn't have to be difficult or boring. By taking you on a Monday-through-Friday workweek adventure with a pair of programmers, Paolo Perrotta helps make mastering the art of metaprogramming both straightforward and entertaining.
The book is packed with:
Pragmatic examples of metaprogramming in action, many of which come straight from popular libraries or frameworks, such as Rails. Programming challenges that let you experiment and play with some of the most fun, "out-there" metaprogramming concepts. Metaprogramming spells—34 practical recipes and idioms that you can study and apply right now, to write code that is sure to impress.
Whether you're a Ruby apprentice on the path to mastering the language or a Ruby wiz in search of new tips, this book is for you.
METAPROGRAMMING RUBY: PROGRAM LIKE THE RUBY PROS provides tips on metaprogramming to programmers at all levels, from beginners to experts, and explains metaprogramming techniques in a basic style. From understanding the basics of Ruby's options and models to applying metaprogramming in daily work and projects, this packs in fine examples of metaprogramming in action and over thirty practical recipes to write better code. Any Ruby collection must have this. Describes metaprogramming as an essential component of Ruby. This book helps readers to master the art of metaprogramming. It is packed with pragmatic examples of metaprogramming in action, many of which come straight from popular libraries or frameworks, such as Rails; programming challenges that let you experiment and play.