Buy Effective Ruby Book by Peter J. Jones - Bookswagon
close menu
Bookswagon
search
My Account
Home > Computer programming / software engineering > Programming and scripting languages: general > Effective Ruby: 48 Specific Ways to Write Better Ruby
Effective Ruby: 48 Specific Ways to Write Better Ruby

Effective Ruby: 48 Specific Ways to Write Better Ruby


     0     
5
4
3
2
1



Out of Stock


Notify me when this book is in stock
X
About the Book

If you’re an experienced Ruby programmer, Effective Ruby will help you harness Ruby’s full power to write more robust, efficient, maintainable, and well-performing code. Drawing on nearly a decade of Ruby experience, Peter J. Jones brings together 48 Ruby best practices, expert tips, and shortcuts—all supported by realistic code examples.

 

Jones offers practical advice for each major area of Ruby development, from modules to memory to metaprogramming. Throughout, he uncovers little-known idioms, quirks, pitfalls, and intricacies that powerfully impact code behavior and performance.

Each item contains specific, actionable, clearly organized guidelines; careful advice; detailed technical arguments; and illuminating code examples. When multiple options exist, Jones shows you how to choose the one that will work best in your situation.

 

Effective Ruby will help you systematically improve your code—not by blindly following rules, but by thoroughly understanding Ruby programming techniques.

 

Key features of this concise guide include

  • How to avoid pitfalls associated with Ruby’s sometimes surprising idiosyncrasies
  • What you should know about inheritance hierarchies to successfully use Rails (and other large frameworks)
  • How to use misunderstood methods to do amazingly useful things with collections
  • Better ways to use exceptions to improve code reliability
  • Powerful metaprogramming approaches (and techniques to avoid)
  • Practical, efficient testing solutions, including MiniTest Unit and Spec Testing
  • How to reliably manage RubyGem dependencies
  • How to make the most of Ruby’s memory management and profiling tools
  • How to improve code efficiency by understanding the Ruby interpreter’s internals


Table of Contents:

Foreword xi

Preface xiii

Acknowledgments xvii

About the Author xix

 

Chapter 1: Accustoming Yourself to Ruby 1

Item 1: Understand What Ruby Considers to Be True 1

Item 2: Treat All Objects as If They Could Be nil 3

Item 3: Avoid Ruby’s Cryptic Perlisms 6

Item 4: Be Aware That Constants Are Mutable 9

Item 5: Pay Attention to Run-Time Warnings 12

 

Chapter 2: Classes, Objects, and Modules 17

Item 6: Know How Ruby Builds Inheritance Hierarchies 17

Item 7: Be Aware of the Different Behaviors of super 24

Item 8: Invoke super When Initializing Subclasses 28

Item 9: Be Alert for Ruby’s Most Vexing Parse 31

Item 10: Prefer Struct to Hash for Structured Data 35

Item 11: Create Namespaces by Nesting Code in Modules 38

Item 12: Understand the Different Flavors of Equality 43

Item 13: Implement Comparison via “<=>” and the Comparable Module 49

Item 14: Share Private State through Protected Methods 53

Item 15: Prefer Class Instance Variables to Class Variables 55

 

Chapter 3: Collections 59

Item 16: Duplicate Collections Passed as Arguments before Mutating Them 59

Item 17: Use the Array Method to Convert nil and Scalar Objects into Arrays 63

Item 18: Consider Set for Efficient Element Inclusion Checking 66

Item 19: Know How to Fold Collections with reduce 70

Item 20: Consider Using a Default Hash Value 74

Item 21: Prefer Delegation to Inheriting from Collection Classes 79

 

Chapter 4: Exceptions 85

Item 22: Prefer Custom Exceptions to Raising Strings 85

Item 23: Rescue the Most Specific Exception Possible 90

Item 24: Manage Resources with Blocks and ensure 94

Item 25: Exit ensure Clauses by Flowing Off the End 97

Item 26: Bound retry Attempts, Vary Their Frequency, and Keep an Audit Trail 100

Item 27: Prefer throw to raise for Jumping Out of Scope 104

 

Chapter 5: Metaprogramming 107

Item 28: Familiarize Yourself with Module and Class Hooks 107

Item 29: Invoke super from within Class Hooks 114

Item 30: Prefer define_method to method_missing 115

Item 31: Know the Difference between the Variants of eval 122

Item 32: Consider Alternatives to Monkey Patching 127

Item 33: Invoke Modified Methods with Alias Chaining 133

Item 34: Consider Supporting Differences in Proc Arity 136

Item 35: Think Carefully Before Using Module Prepending 141

 

Chapter 6: Testing 145

Item 36: Familiarize Yourself with MiniTest Unit Testing 145

Item 37: Familiarize Yourself with MiniTest Spec Testing 149

Item 38: Simulate Determinism with Mock Objects 152

Item 39: Strive for Effectively Tested Code 156

 

Chapter 7: Tools and Libraries 163

Item 40: Know How to Work with Ruby Documentation 163

Item 41: Be Aware of IRB’s Advanced Features 166

Item 42: Manage Gem Dependencies with Bundler 170

Item 43: Specify an Upper Bound for Gem Dependencies 175

 

Chapter 8: Memory Management and Performance 179

Item 44: Familiarize Yourself with Ruby’s Garbage Collector 179

Item 45: Create Resource Safety Nets with Finalizers 185

Item 46: Be Aware of Ruby Profiling Tools 189

Item 47: Avoid Object Literals in Loops 195

Item 48: Consider Memoizing Expensive Computations 197

 

Epilogue 201

 

Index 203



About the Author :
Peter J. Jones is a freelance software developer and a senior instructor for programming workshops taught by Devalot.com. He has been programming in Ruby since 2005, and has written and taught several development workshops, including an 11-week Ruby class for beginners.


Best Sellers


Product Details
  • ISBN-13: 9780133847079
  • Publisher: Pearson Education (US)
  • Publisher Imprint: Addison Wesley
  • Language: English
  • Sub Title: 48 Specific Ways to Write Better Ruby
  • ISBN-10: 0133847071
  • Publisher Date: 08 Sep 2014
  • Binding: Digital download
  • No of Pages: 240
  • Weight: 1 gr


Similar Products

Add Photo
Add Photo

Customer Reviews

REVIEWS      0     
Click Here To Be The First to Review this Product
Effective Ruby: 48 Specific Ways to Write Better Ruby
Pearson Education (US) -
Effective Ruby: 48 Specific Ways to Write Better Ruby
Writing guidlines
We want to publish your review, so please:
  • keep your review on the product. Review's that defame author's character will be rejected.
  • Keep your review focused on the product.
  • Avoid writing about customer service. contact us instead if you have issue requiring immediate attention.
  • Refrain from mentioning competitors or the specific price you paid for the product.
  • Do not include any personally identifiable information, such as full names.

Effective Ruby: 48 Specific Ways to Write Better Ruby

Required fields are marked with *

Review Title*
Review
    Add Photo Add up to 6 photos
    Would you recommend this product to a friend?
    Tag this Book Read more
    Does your review contain spoilers?
    What type of reader best describes you?
    I agree to the terms & conditions
    You may receive emails regarding this submission. Any emails will include the ability to opt-out of future communications.

    CUSTOMER RATINGS AND REVIEWS AND QUESTIONS AND ANSWERS TERMS OF USE

    These Terms of Use govern your conduct associated with the Customer Ratings and Reviews and/or Questions and Answers service offered by Bookswagon (the "CRR Service").


    By submitting any content to Bookswagon, you guarantee that:
    • You are the sole author and owner of the intellectual property rights in the content;
    • All "moral rights" that you may have in such content have been voluntarily waived by you;
    • All content that you post is accurate;
    • You are at least 13 years old;
    • Use of the content you supply does not violate these Terms of Use and will not cause injury to any person or entity.
    You further agree that you may not submit any content:
    • That is known by you to be false, inaccurate or misleading;
    • That infringes any third party's copyright, patent, trademark, trade secret or other proprietary rights or rights of publicity or privacy;
    • That violates any law, statute, ordinance or regulation (including, but not limited to, those governing, consumer protection, unfair competition, anti-discrimination or false advertising);
    • That is, or may reasonably be considered to be, defamatory, libelous, hateful, racially or religiously biased or offensive, unlawfully threatening or unlawfully harassing to any individual, partnership or corporation;
    • For which you were compensated or granted any consideration by any unapproved third party;
    • That includes any information that references other websites, addresses, email addresses, contact information or phone numbers;
    • That contains any computer viruses, worms or other potentially damaging computer programs or files.
    You agree to indemnify and hold Bookswagon (and its officers, directors, agents, subsidiaries, joint ventures, employees and third-party service providers, including but not limited to Bazaarvoice, Inc.), harmless from all claims, demands, and damages (actual and consequential) of every kind and nature, known and unknown including reasonable attorneys' fees, arising out of a breach of your representations and warranties set forth above, or your violation of any law or the rights of a third party.


    For any content that you submit, you grant Bookswagon a perpetual, irrevocable, royalty-free, transferable right and license to use, copy, modify, delete in its entirety, adapt, publish, translate, create derivative works from and/or sell, transfer, and/or distribute such content and/or incorporate such content into any form, medium or technology throughout the world without compensation to you. Additionally,  Bookswagon may transfer or share any personal information that you submit with its third-party service providers, including but not limited to Bazaarvoice, Inc. in accordance with  Privacy Policy


    All content that you submit may be used at Bookswagon's sole discretion. Bookswagon reserves the right to change, condense, withhold publication, remove or delete any content on Bookswagon's website that Bookswagon deems, in its sole discretion, to violate the content guidelines or any other provision of these Terms of Use.  Bookswagon does not guarantee that you will have any recourse through Bookswagon to edit or delete any content you have submitted. Ratings and written comments are generally posted within two to four business days. However, Bookswagon reserves the right to remove or to refuse to post any submission to the extent authorized by law. You acknowledge that you, not Bookswagon, are responsible for the contents of your submission. None of the content that you submit shall be subject to any obligation of confidence on the part of Bookswagon, its agents, subsidiaries, affiliates, partners or third party service providers (including but not limited to Bazaarvoice, Inc.)and their respective directors, officers and employees.

    Accept

    Fresh on the Shelf


    Inspired by your browsing history


    Your review has been submitted!

    You've already reviewed this product!
    Your IP: 216.73.217.110 IN