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
《期权36课:基本知识与实战策略》内容简介:这本书的目标读者是刚开始学习期权以及有一定期权基础,但又想提高实践与理论相结合能
《智能制造基础共性标准研究成果(三)》内容简介:2015年开始,工业和信息化部与财政部共同实施了“智能制造综合标准化与新模式应
《石门铭》内容简介:《石门铭》,又称《泰山羊祉开复石门铭》。北魏宣武帝永平二年(五〇九)立,记述了梁、秦二州刺史羊祉和左校
《Hadoop技术内幕:深入解析MapReduce架构设计与实现原理》内容简介:“Hadoop技术内幕”共两册,分别从源代码的角度对“Common+H
基于Pro/E注塑模具CAD设计-(含光盘) 本书特色 《基于Pro/E注塑模具CAD设计/全国高职高专规划教材·机械设计制造系列》是在工作过程系统化理论的课程...
《亚非诸国文学研究的学术历程》内容简介:本书是《中国外国文学研究的学术历程》总12卷之第12卷。本卷主要介绍亚非地区除日本、印
《梁庄十年》内容简介:2010年,《中国在梁庄》首次出版,向我们展现了一个急速变化的时代下的中国村庄的变迁。十年之后,作者梁鸿
《设计师不读书》是一本为创意专业人士“量身打造”,激发他们设计灵感的书。创意总监、广告撰稿人和设计的倡导者奥斯汀·豪对创
全国英语等级考试词汇必备第二级 本书特色 针对教育部*新颁布的《全国英语等级考试大纲(全新版)》,未来教育在已出版成功的词汇书的基础上,对《全国英语等级考试词汇...
《QtCreator快速入门》作为全面介绍Qt、QtCreator和QtQuick的入门级教材,也是市面上第一套详细介绍QtCreator和QtQuick的教材...
本书分为四个部分,每部分内容都由一个研究案例引出。第一部分介绍了如何保证系统的生存,即维护系统正常运行。第二部分介绍了如
《最新《事业单位会计准则》解读与操作示范》内容简介:《最新事业单位会计准则:解读与操作示范》围绕财政部最新修订的《事业单位
本书介绍了正交频分复用(OFOM)技术的原理及其在无线通信领域内的应用。全书共分10章。第1章简要介绍了移动通信的发展现状、无线
Mac OS X Leopard Edition(影印版) 本书特色 为什么开创Missing Manual系列当知识富有吸引力、条理清楚并有趣味时,人们的学习...
《许包野传》内容简介:用好用活丰富的党史资源, 铭记革命先烈,弘扬革命精神, 激励人民不断开拓前进。本丛书力求真实反映雨花台
《3G技术问答》从3G空中接口的四个主流标准(TD-SCDMA、WCDMA、cdma2000和WiMAX)的内容中精选了五百多个问题,以“知识问答”的形
WebAppSuccessByDANZAMBONINIForewordByMARKBOULTONMostexistingwebappbookscoveraspe...
GNUEmacsisthemostpopularandwidespreadoftheEmacsfamilyofeditors.Itisalsothemostpo...
ThebookcoverstheforthcomingPylons0.9.7releaseandisavailbleforfreetoreadhereonlin...
《短视频拍摄与制作(微课版)》内容简介:随着移动互联网的高速发展,短视频行业也发展迅猛,成为5亿多人的信息关注、分享和传播的