For many programmers, discovering Ruby is a revelation. They are overjoyed by how elegantly and succinctly they can state problems in the language. But then the real world creeps in, and that joy gradually wanes as the code becomes cluttered with distracting edge case scenarios, error handling, and checks for nil.
Confident Ruby is a guide to recapturing the joy of writing Ruby by employing small patterns and stylistic choices to make each method tell a coherent story. Over the course of 32 patterns, you’ll learn how to isolate uncertainty at the borders of your code; how to avoid repetitive conditionals; and how to liberate your code from the chore of nil-checking. You’ll discover the four parts of a method, and how to use those parts to construct a narrative. Following along with real-world refactoring sessions, you’ll learn how to apply these lessons to legacy code.
Whether you are a novice or an experienced Ruby hacker, this book will help you become a more confident and joyful programmer.
Introduction
- Ruby meets the real world
- Confident code
- A good story, poorly told
- Code as narrative
- The four parts of a method
- 3.times { rejoice! }
- Collecting Input
Sending a strong message
- Conditionally call conversion methods
- Define your own conversion protocols
- Define conversions to user-defined types
- Use built-in conversion functions
- Use the Array() conversion function to array-ify inputs
- Define conversion functions
- Replace “string typing” with classes
- Wrap collaborators in Adapters
- Use transparent adapters to gradually introduce abstraction
- Reject unworkable values with preconditions
- Use #fetch to assert the presence of Hash keys
- Document assumptions with assertions
- Handle special cases with a Guard Clause
- Represent special cases as objects
- Represent do-nothing cases as null objects
- Substitute a benign value for =nil=
- Use #fetch for defaults
- Use symbols as placeholder objects
- Bundle arguments into parameter objects
- Yield a parameter builder object
- Receive policies instead of data
Delivering Output
- Write total functions
- Call back instead of returning
- Represent failure with a benign value
- Represent failure with a special case object
- Return a status object
- Yield a status object
- Signal early termination with =throw=
Handling Failure
- Prefer top-level rescue clause
- Use checked methods for risky operations
- Use bouncer methods
Refactoring for Confidence
- MetricFu
- Stringer
- Parting Words
《2016年职称英语考试历年真题详解及全真模拟试卷A级(理工类)》内容简介:人事部组织的全国统一标准的职称英语考试划分为综合、理
本书是美国艺术与设计专业品牌教材,是关于字体设计应用的基础知识的基础读物,同时具有一般广泛性,从字体设计的宏观到微观,都
Creativityisnolongerthesoleterritoryofthedesignerandothercreativeprofessionals.A...
《通信类毕业生求职宝典》找一份让自己满意且适合自身发展的工作对于即将走向社会的同学们而言尤为重要。通信类专业毕业生知识覆
《创业就是构建美好关系》内容简介:创业就是一场修行,谋生又谋爱,爱就是一种美好链接,创业者和周遭的关系,将影响企业发展和人
作者阿兰·F·祖尔等的基于他们对应用科学家讲授统计与R的丰富经验,为读者献上了《R语言初学者指南》这本书。为了避免同时讲授R
《学好电工技术500个问与答》内容简介:本书答共14章,分别是电工常用元器件,变电与配电装置,动力用电设备与控制,机床电路,照明
尼可拉斯.卡爾(NicholasG.Carr)知名作家兼思想家,專研商業策略、資訊科技及兩者的交叉點,在《哈佛商業評論》寫過包括〈IT沒有
《电子商务网页设计》内容简介:本书针对中等职业学校电子商务专业和计算机类专业的网页设计与制作的教材或参考书,共分十二个项目
《Java程序员面试宝典》不同于其他Java程序书籍的主要特点如下。?唯一性本书是国内市场上唯一介绍Java程序员求职面试技巧的图书和
Doyouenjoywritingsoftware,exceptforthedatabasecode?Hibernate:ADevelopersNotebook...
本书由浅入深、循序渐进地讲解了Android系统的软件安全、逆向分析与加密解密技术。包括Android软件逆向分析和系统安全方面的必备
《JSP网站开发详解》介绍了使用JSP及其相关技术开发网络应用程序的基础知识和方法,全书共分为3个部分。其中第1部分介绍了使用JS
精通Oracle SQL-(第2版) 本书特色 《精通oracle sql(第2版)》语言精炼、风趣,所涵盖的内容涉及sql核心、sql执行、分析函数、联结、测...
本书提出了一个框架,用于分析程序设计语言的语法、操作和语义性质,该框架基于称为类型化λ演算的数学系统。λ演算的主要特色是
《中国特色消费经济理论与实证研究》内容简介:消费问题是个热门话题,不仅得到广大群众的关注,而且受到党和政府的高度重视。本书
Thedazzlingnewmasterworkfromtheprophetofsiliconvalley.JaronLanieristhebestsellin...
很多事物中都存在组成(成分、构成)问题。作者创立的组成论为此提供统一的认识模型、分析工具、计算方法和原理。它通过广义集合
《众妙之门——抓住访客心理的网页设计》是知名Web设计网站SmashingMagazine关于网页设计心理学的知识及经验的分享。这些文章都是
汇编语言-(第2版) 内容简介 汇编语言是各种CPU提供的机器指令的助记符的集合,人们可以用汇编语言直接控制硬件系统进行工作。汇编语言是很多相关课程(如数据结构...