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
CSS是层叠样式表的简称,通过它可控制网页样式并允许将样式信息与网页内容分离。《CSS终极参考手册》是CSS的最佳参考书籍,共18章
《辽金元诗鉴赏》内容简介:本书是以辽金元三代的诗歌作品——包含诗、词、曲为基础,而编选、注释、鉴赏的广义诗选。共选择经典作
《三个存钱罐:金融学教授的儿童财商启蒙课》内容简介:本书从家长的角度,通过一个个故事和亲身体验系统地探讨了如何提高孩子财商
本书通过分析ReactOS的源代码介绍了Windows内核各个方面的结构、功能、算法与具体实现。全书从“内存管理”、“进程”、“进程间
《空战百年》内容简介:这是一本从过去到未来,从技术到战术,从社会学的意涵到艺术的审美,全方位对空战进行解析的著作。从“一战
《算法之美》内容简介:我们所有人的生活都受到有限空间和有限时间的限制,因此常常面临一系列难以抉择的问题。在一天或者一生的时
《启蒙之旅》内容简介:不管是太平年月还是战时,船总是危险的。这是一则航海故事,但里面没有暴风雨,没有失事,没有营救,没有看
Python金融大数据分析 本书特色 python凭借其简单、易读、可扩展性以及拥有巨大而活跃的科学计算社区,在需要分析、处理大量数据的金融行业得到了广泛而迅速...
《马克思主义理论简明读本》内容简介:本书是由武汉理工大学马克思主义学院组织编写的,内容涵盖两个板块,一是马克思主义基本原理
五笔字型经典教程 本书特色 本书是一本关于五笔字型输入法入门及应用的教程。全书共分为9章,包括指法训练、五笔字型输入法、拆分汉字、录入汉字、简码、词组、容错码、...
《pcDuino开发实战》内容简介:本书共分为四篇,由浅入深地讲解pcDuino的开发使用。第一篇为基础篇,包括第1~3章,首先介绍了Ardui
《海蒂的花园》内容简介:任何时候花园都不会尽如人意,无论付出多少努力;任何时候花园里都能找到美好,无论历经多少挫折。在连餐
Evernoticethat-inspiteoftheirpervasiveness-designingwebapplicationsisstillchalle...
本书生动展现了各种科学领域与人们生活的结合,其深度令科学家感叹、文笔令作家叹服,核心价值在于作者展现的人类对科学的恒久敬
《智能教育:让孩子站在人工智能的肩膀上适应未来》内容简介:人工智能等新技术正在悄然改变着教育行业的方方面面,如何应对人工智
《Processing开发实战》内容简介:Processing简单易学的界面和编程风格,使很多机器人爱好者或电子制作爱好者,可以借助它完成机器
《撑下去便是一切》内容简介:这是一本讲述如何通向成功的励志实用功能性图书,描述了一个年轻人的艰辛历程。主人公的思考、总结和
各位程序员一定希望自己编写的代码是能让老板赞赏、满意的代码;是能让客户乐意掏钱购买的代码;是能让使用者顺利使用的代码;是
《黄金白银投资与理财》内容简介:本书从认识黄金和白银的特性入手,分析了黄金以及白银的金属属性和货币属性,阐述了黄金与白银市
在线阅读本书BookDescriptionIDEO,thewidelyadmired,award-winningdesignanddevelopmentfirm...