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
《一本书读懂互联网思维》内容简介:每个人都看得懂的互联网思维入门书。本书从互联网思维的定义到互联网思维应用的具体案例表现。
Mostcompanieshavemassiveamountsofdataattheirdisposal,yetfailtoutilizeitinanymean...
設計需要衝擊才能併發出更多精彩的概念與創作,如果你老在同一種設計手法中打轉,不知該如何突破,請看一線設計師如何在相同的主
JeffcTapper,Adobe技术社区最有影响力的专家之一,拥有丰富的Web开发经验,客户包括摩根士丹利、IBM、道琼斯等公司。他还是WebcDev
CSS3isthetechnologybehindmostoftheeye-catchingvisualsontheWebtoday,buttheofficia...
《我们为什么上瘾》内容简介:科普作家萨拉维茨生于一个美国犹太中产家庭,她在20世纪80年代就读于哥伦比亚大学时,不幸对药物成瘾
本书根据最新的2.6.24内核为基础。在讲述方式上,本书注重实例分析,尽量在讨论“如何做”的基础上,深入讨论为什么要这么做,从
本书论述了信息检索的有关概念与基本知识,以及Internt重要的中外文搜索引擎与检索技巧,介绍了网上各类型电子信息和重要专题信息
KenAulettahaswrittenthe"AnnalsofCommunications"columnforTheNewYorkersince1992.He...
《反黑风暴·网站入侵与脚本技术快速防杀》由浅入深、图文并茂地再现了网站入侵与脚本技术快速防杀的全过程,内容涵盖:Windows系
《从0到1写方案》内容简介:基于全网10万+学员订阅的爆款课程《如何成为年入百万的方案高手》《15堂零基础系统方案课》内容来进一步
《爱上古诗文》内容简介:一年一度的上海小学生古诗文大会暨古诗文“桂冠少年”选拔活动即将在9月份启动,承办方上海教育报刊总社《
《我读:陪你读到世界尽头》内容简介:《我读:陪你读到世界尽头》是由梁文道主讲的书评集。用最简洁直白的方式带领读者领略好书的
《黑客攻防与网络安全从新手到高手(实战篇)》内容简介:本书在剖析用户进行黑客防御中迫切需要或想要用到的技术时,力求对其进行
并行程序设计(第2版) 本书特色 本书系统介绍并行程序设计原理及应用。除介绍常用的一些算法范例,包括分治、流水、同步计算、主从及工作池,还介绍了一些常用的经典数...
《通信企业市场营销》结合作者多年来从事电信企业市场营销理论研究的成果,以及我国电信企业的市场营销活动和实践,论述了市场营
《机械修理工艺与技能训练》内容简介:该课程主要介绍了设备修理的基本知识,通用零件的故障诊断与修理;减速器的故障诊断与修理;
《贫困的复杂图景与反贫困的多元路径》内容简介:本书在实地田野调研的基础上,通过宏观、微观考察民族地区农村贫困的复杂图景及致
《心理学与九型人格》内容简介:追求尽善尽美的完美型、古道热肠的奉献型、脚踏实地的实干型、充满艺术气息的浪漫型、头脑冷静的观
《绘画高手这样画·素描静物》内容简介:书中分为3个部分,第1章节为基础知识章节;第二章节为物体质感的绘制章节;第三章节绘画高