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
《设计法则100》是一本关于如何做好设计的思想智能手册。什么是好的设计?怎样才能做好设计?设计师们在面对各种项目要求和挑战时
资深Java专家10年经验总结,全程案例式讲解,首本全面介绍Java多线程编程技术的专著结合大量实例,全面讲解Java多线程编程中的并
《哥德巴赫猜想》内容简介:本书收集了作者有代表性的纪实文学作品,所有篇章皆是具体人物的展现,所展现人物,皆为中国现当代时期
群智能算法及化工优化问题 内容简介 数学建模方法是研究化工过程的一种有效方法,由于化工过程影响因素多、波动大、反应机理复杂,因此,所建立的模型大多比较复杂,用传...
《IP电话技术与软交换(第2版)》较全面地介绍了与IP电话和软交换有关的技术。主要包括IP电话的基本概念,IP电话网的一般结构和IP电
Web Color Design:设计师谈网页配色 内容简介 本书是为网页设计师量身定制的配色方案专业书籍。全书共分七个部分,分别结合丰富的实例讲述了配色基础知...
罗振宇、丹尼尔•平克、赛斯•高汀、丹•艾瑞里、谢家华、阿里安娜•赫芬顿强烈推荐!美国亚马逊2013年年度商业&投资类图书榜前20名!
在本书中,作者从设计思维的视角,探索了利用信息技术将医疗保健业引入体验经济的方式。在体验经济中,患者角色将转型为医疗产业
本书以IEEE802系列标准为主介绍局域网与城域网的相关技术,涉及lOMbps以太网、快速以太网、千兆位以太网、万兆位以太网、交换式以
《素描初步——静物绘制基础教程》内容简介:静物画是学习素描中重要的一部分,初学者在学习时会遇到造型不准确、画不准结构、比例
《梳理:从混乱到有序,人生提效50%》内容简介:毕业在即,考研还是工作?自己想要的到底是什么?很迷茫; 逛知乎、看豆瓣、浏览微
TheauthorofFreeCultureshowshowweharmourchildren—andalmostanyonewhocreates,enjoys...
JAVA程序员修炼之道 本书特色 《java程序员修炼之道》分为四部分,**部分全面介绍java7的新特性,第二部分探讨java关键编程知识和技术,第三部分讨论...
《构建高性能Web站点》内容简介:本书围绕如何构建高性能Web站点,从多个方面、多个角度进行了全面的阐述,涵盖了Web站点性能优化的
《中国工程船研发史》内容简介:本书是中国船舶研发史丛书之一。工程船是专门用于各种水上、水下工程建设的船舶。本书从工程船定义
Onlinecommunitiesofferawiderangeofopportunitiestoday,whetheryouresupportingacaus...
本书采用结构化方法来介绍计算机系统,书的内容完全建立在“计算机是由层次结构组成的,每层完成规定的功能”这一概念之上。作者
BrandsAtoZ:是一套讲述富于独立性和创造性的品牌故事的丛书.本书详细探寻了每一个被选择品牌的历史,反映了其公司文化,并展示了其
《Redis开发与运维》内容简介:本书全面讲解Redis基本功能及其应用,并结合线上开发与运维监控中的实际使用案例,深入分析并总结了
Cisco IP 电话疑难解析 内容简介 本书指导读者学习怎样分析和纠正IP电话网络中的问题。全书共分18章,分别介绍了疑难解析方法学、IP电话体系结构、疑难解...