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
高性能通信网络(原书第2版),ISBN:9787111094456,作者:(美)JeanWalrand,(美)PravinVaraiya著;张艳等译目录 出版者...
《Struts2权威指南:基于WebWork核心的MVC开发》介绍的Struts2已经完全超出了Struts1框架原有的高度,Struts2建立在Struts1...
《新手读财报》内容简介:本书作为财务分析的入门级读物,以“业”“财”融合为基调,充分强调财务源于业务,在理解公司业务的基础
《屏幕字体设计:从符号语言到意义构建》内容简介:屏幕作为一种新型媒介,其出现带来了更复杂、更具创造性的挑战。想要全面了解屏
《把生活修炼到你喜欢的模样》内容简介:这一路行走,你得跟随着自己,为自己奔跑,抵制别人的驾驭。让自己的灵魂做主,即使在风烛
《HAWQ数据仓库与数据挖掘实战》内容简介:ApacheHAWQ是一个SQL-on-Hadoop产品,它非常适合用于Hadoop平台上快速构建数据仓库系统。
《天神和人》内容简介:本书讲述中西方的神话故事,主要是西方的希腊神话中宇宙体系的构建者和中华文明的古老神话中关于宇宙形成的
《全能鼓手实战教程——648句技巧训练》内容简介:本书是一本鼓手必备的练习宝典。涵盖了爵士鼓、小军鼓等各类鼓乐学习过程中初级、
《杨家将演义(插图本)》内容简介:杨家将故事,是我国民间流传最广的英雄传奇故事之一。《杨家将演义》为明人编撰的一部杨家将小
《SQL权威指南(第4版)》为SQL名著中文版,兼顾技术与实践,全面细致介绍高级技术,致力于打造SQL编程专家。《SQL权威指南(第4版)
奈良美智出生於1959年12月5日,日本青森縣弘前市人。是日本現代美術界極具影響力的畫家。1981~1988年在愛知縣立藝術大學和研究所
《海蒂的花园》内容简介:任何时候花园都不会尽如人意,无论付出多少努力;任何时候花园里都能找到美好,无论历经多少挫折。在连餐
《物联网渗透测试》内容简介:本书介绍物联网渗透测试的原理和实用技术。主要内容包括IOT威胁建模、固件分析及漏洞利用、嵌入式web
ActionScript3.0是一种功能强大的面向对象编程语言。本书分五大部分全面讲解ActionScript3.0动画。第一部分介绍了ActionScript...
本书作者多年致力于艺术、设计的教学,并在自学软件的过程中获得启示,每个单元均以美学角色切入,再引导实际操作,通过作品来呈
书由浅入深,全面、系统地介绍了Node.js开发技术。书中提供了大量有针对性的实例,供读者实践学习,同时提供了大量的实践练习题及
《MakingIt:設計師一定要懂的產品製造知識》***美國知名設計公司IDEO的總裁TimBrown說:『MakingIt,對於設計師來說,是本無價
《淘宝店铺经营管理一册通》内容简介:《淘宝店铺经营管理一册通》基于多家淘宝金冠卖家多年来开店的经验,针对淘宝管理和客服进行
本书从实践者的角度,在讲解Docker高级实践技巧的同时,深入到源代码层次,为读者梳理出Docker容器技术和基于Docker的容器云技术
计算机密码应用基础 内容简介 本书是在四川大学密码学公共选修课所用的讲义基础上编写而形成的。内容涉及密码学中几大“核心”领域,包括分组密码、香农理论、序列密码、...