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
《知足知不足:季羡林精读》内容简介:《知足知不足:季羡林精读》是著名东方学学者季羡林一生散文作品的精选集,包括《赋得永久的
《天人合一》内容简介:“天人合一”由宋代著名思想张载明确提出,是中国传统思想中经久不衰的思想话题,集中体现了人与自然和谐相
《网络与通信技术百科全书》是一本关于网络技术和通信技术的百科全书,内容涉及了到目前为止网络与通信方面的各种技术和应用。《
Ifyouveeverbeenintroducedtoanewemployeeattheofficeas"theguywhogotdrunkattheChris...
家用游戏机简史 本书特色 本书以时间为轴,重新厘清了30余年游戏主机的成长历程,梳理了游戏产业的发展脉络。从幕后开发、技术变革、游戏策略等多重角度,解读五次游戏...
《数学战略家:谷超豪传》内容简介:《谷超豪传(数学战略家)》是《大家丛书》系列丛书之一。谷超豪,数学家。复旦大学教授,中国科
《消防安全技术综合能力考前必刷卷》内容简介:本书为备考一级注册消防工程师《消防安全技术综合能力》科目编写,共包括三套真题和
与传统的用户应用程序开发不同,内核环境更加复杂多变,任何问题都会严重影响系统的稳定性、安全性和性能,所以一定要确保内核代
《天津滨海新区史话》内容简介:天津滨海新区地处海河下游、渤海湾西岸,河海相依,临海近都,区位优越。这里曾是中国人民抗击外侮
《区块链将如何重新定义世界》内容简介:本书作为国内率先出版的原创性区块链启蒙读物,博采众长,汇集了众多专家学者对于区块链的
《网页配色实用手册》在日常生活中,色彩早已广泛地深入到人们的精神生活和物质生活中,它是一种能够激发情感、刺激感官的重要元
《王学研究(第六辑)》内容简介:《王学研究》由贵阳学院阳明学与黔学研究院主办,围绕阳明学研究,征集国内外学者的论文,汇集阳
Pro/Engineer Wildfire2.0特征与三维实体建模 内容简介 本书分为Pro/Engineer Wildfire 2.0概览、草图绘图、基准特征...
《硅谷工程师爸爸的超强数学思维课:建立孩子的几何思维》内容简介:如何开发孩子的数学思维?如何让孩子把数学与生活结合起来,学
广告语英国DK经典作品艺术排行榜冠军姊妹篇独特3D图立体图解析全球最标志建筑!主要卖点•世界建筑史上最著名的50余座全面解析•分
如今的网站和内联网已经变得比以前越来越大,越来越有价值,而且越来越复杂,同时其用户也变得更忙,也更加不能容忍错误的发生。
《未来零售》内容简介:“新零售”概念提出至今,各家零售企业已触发了一系列迭代动作,而突如其来的疫情,更是给整个新零售行业按
数据挖掘教程 内容简介 这本书的文字内容主要参考了美国麻省理工学院的数据挖掘开放讲义、国外许多大学老师关于数据挖掘课程的教学资料以及网络上对有关算法的介绍材料。...
本书初版于1983年,是20世纪80年代轰动知识界的“走向未来丛书”之一种。作者采用中西对比的视角,探讨了近代科学技术结构发展的
《赢在执行》内容简介:职场上的成功,需要我们通过执行去获得,我们不能做语言的巨人,行动的矮子,而应当不断提高自己的执行力,