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
《漫画小白学漫画,这本就够了!(基础综合)》内容简介:一直以来,漫画都受到大众的热爱和追捧,尤其是日本漫画和美国漫画。国内
博客(blog),这个由“网络日志”(weblog)派生出来的词,早已跳脱了“日志”的范畴,担当起信息传播、情感交流、产品宣传等等职责
《20世纪中国唯识学史要》内容简介:本书是海内外第一部对20世纪佛教唯识学思潮作出系统梳理的研究专著,以20世纪中国法相唯识学发
《元宇宙:数字化生存新机遇》内容简介:社会生活和经济活动将向元宇宙大迁徙。我们将生活在一个真实与虚拟共生的新世界。在这种新
《张晋张谦集校笺》内容简介:本书为“清代诗人别集丛刊”中的一种,着眼于深度整理清初甘肃著名诗人张晋和张谦的诗集。书稿整理了
《Cocos2d-x 3.x游戏开发实战》内容简介:《Cocos2d-x 3.x游戏开发实战》是一本介绍Cocos2d-x游戏引擎的实用图书,全面介绍了最新的
《我曾与大海为邻》内容简介:1962年,一位21岁的小学老师响应党的号召,主动要求下放到农村,从人民教师变成公社社员。他来到渔村
《什么是高中物理》内容简介:几乎囊括了高中物理的所有知识点,流畅而有趣地讲述这些内容的来龙去脉,并以一个清晰的脉络串起来,
专转本计算机应用基础考试必读 内容简介 本书是一部专转本考试中计算机应用基础科目的辅导用书,内容涉及信息技术概述、计算机组成原理、计算机软件、计算机网络与因特网...
《为什么是中国》内容简介:金一南将军全新著作,一部感天动地的奋斗史诗,一代一代人铸就的中华之魂。以广阔全面的视野、一以贯之
《骨科循证医学》内容简介:本书共分五部分23章,包括绪论、脊椎疾病循证医学、骨折疾病循证医学、慢性运动损伤循证医学、恶性骨肿
数据库基础与应用-Access 2010 本书特色 付兵主编的《数据库基础与应用:Access 2010》共10章,从数据库的基础理论开始,以“学生成绩管理”系...
Geneticalgorithmsareplayinganincreasinglyimportantroleinstudiesofcomplexadaptive...
《思维导图:文言文满分学习法》内容简介:本书运用思维导图这种可视化的思维技术,运用图文并茂的形式和严谨的逻辑结构将中学阶段
《中外民歌钢琴曲集 1》内容简介:从这套乐谱的功能来看,除了作为钢琴教材还可以作为多声写作和小品写作的例谱,配器课的习题集,
本书采用结构化方法来介绍计算机系统,书的内容完全建立在“计算机是由层次结构组成的,每层完成规定的功能”这一概念之上。作者
《理解Unix进程》从Unix编程的基础概念着手,采用循序渐进的方法,详细介绍了Unix进程的内部工作原理。《理解Unix进程》提供的许
Thismust-readtextforallwebdesignersdeliversvitalinformationonhowtoemployinformat...
本书所展示的大量示例网站都是难得一见的佳作,这些网站时而浓墨重彩,时而简洁素雅,为读者带来一场丰富的视觉盛宴。读者可以从
NicholasC.Zakas是一名前端开发顾问、作者和演讲家。在Yahoo!供职超过5年时间,在这期间他曾是Yahoo!首页首席前端工程师和YUI库