You are previewing Eloquent Ruby.
O'Reilly logo
Eloquent Ruby

Book Description

It’s easy to write “correct” Ruby code. But it’s far harder to gain the fluency needed to write great Ruby code. To do that, you need to go beyond syntax and absorb the “Ruby way” of thinking and problem solving. In Eloquent Ruby, Russ Olsen helps you understand Ruby like true Rubyists do—so you can leverage its immense, surprising power.

Olsen draws on years of experience internalizing the Ruby culture and teaching Ruby to other programmers. He guides you to the “Ah Ha!” moments when it suddenly becomes clear why Ruby works the way it does and how you can take advantage of its unique approach.

Eloquent Ruby starts small, answering tactical questions focused on a single statement, method, test, or bug. You’ll learn how to write code that actually looks like Ruby (not Java); why Ruby has so many control structures; how to use strings, expressions, and symbols; and what dynamic typing is really good for.

Next, Olsen turns to bigger questions related to building methods and classes. You’ll discover why Ruby classes contain so many tiny methods, when to use operator overloading, and when to avoid it. Olsen explains how to write Ruby code that writes its own code—and why you’ll want to. He concludes with powerful project-level features and techniques ranging from gems to Domain Specific Languages.

The newest book in the renowned Addison-Wesley Professional Ruby Series, Eloquent Ruby will help you “put on your Ruby-colored glasses” and get results that make you a true believer.

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Praise for Eloquent Ruby
  4. Contents
  5. Foreword
  6. Preface
  7. Acknowledgments
  8. About the Author
  9. Part I. The Basics
    1. Chapter 1. Write Code That Looks Like Ruby
    2. Chapter 2. Choose the Right Control Structure
    3. Chapter 3. Take Advantage of Ruby’s Smart Collections
    4. Chapter 4. Take Advantage of Ruby’s Smart Strings
    5. Chapter 5. Find the Right String with Regular Expressions
    6. Chapter 6. Use Symbols to Stand for Something
    7. Chapter 7. Treat Everything Like an Object—Because Everything Is
    8. Chapter 8. Embrace Dynamic Typing
    9. Chapter 9. Write Specs!
  10. Part II. Classes, Modules, and Blocks
    1. Chapter 10. Construct Your Classes from Short, Focused Methods
    2. Chapter 11. Define Operators Respectfully
    3. Chapter 12. Create Classes That Understand Equality
    4. Chapter 13. Get the Behavior You Need with Singleton and Class Methods
    5. Chapter 14. Use Class Instance Variables
    6. Chapter 15. Use Modules as Name Spaces
    7. Chapter 16. Use Modules as Mixins
    8. Chapter 17. Use Blocks to Iterate
    9. Chapter 18. Execute Around with a Block
    10. Chapter 19. Save Blocks to Execute Later
  11. Part III. Metaprogramming
    1. Chapter 20. Use Hooks to Keep Your Program Informed
    2. Chapter 21. Use method_missing for Flexible Error Handling
    3. Chapter 22. Use method_missing for Delegation
    4. Chapter 23. Use method_missing to Build Flexible APIs
    5. Chapter 24. Update Existing Classes with Monkey Patching
    6. Chapter 25. Create Self-Modifying Classes
    7. Chapter 26. Create Classes That Modify Their Subclasses
  12. Part IV. Pulling It All Together
    1. Chapter 27. Invent Internal DSLs
    2. Chapter 28. Build External DSLs for Flexible Syntax
    3. Chapter 29. Package Your Programs as Gems
    4. Chapter 30. Know Your Ruby Implementation
    5. Chapter 31. Keep an Open Mind to Go with Those Open Classes
  13. Appendix. Going Further
  14. Index
  15. Footnotes
    1. Preface
    2. Acknowledgments
    3. Chapter 1
    4. Chapter 2
    5. Chapter 3
    6. Chapter 4
    7. Chapter 5
    8. Chapter 6
    9. Chapter 7
    10. Chapter 8
    11. Chapter 9
    12. Chapter 10
    13. Chapter 11
    14. Chapter 12
    15. Chapter 13
    16. Chapter 14
    17. Chapter 15
    18. Chapter 16
    19. Chapter 17
    20. Chapter 18
    21. Chapter 19
    22. Chapter 20
    23. Chapter 21
    24. Chapter 22
    25. Chapter 23
    26. Chapter 24
    27. Chapter 25
    28. Chapter 26
    29. Chapter 27
    30. Chapter 28
    31. Chapter 29
    32. Chapter 30
    33. Chapter 31