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
Contourlet变换 内容简介 本书以Contourlet变化在图像处理中的应用为研究对象,介绍了Contourlet变换在影像压缩、超分辨率重建、影像融合...
本书重点讲解Intel系列微处理器(8086/8088、80186/80188、80286、80386、80486、Pentium、PentiumProProc...
ArcSWAT 2009用户指南 本书特色 温切尔编著的《ArcSWAT2009用户指南》内容介绍:SWAT作为一个在非点源污染模拟领域的同际性模型已持续30多...
《公司法学(下)》内容简介:本书通过浅显的文字说明,配以具体案例,对董事的注意义务和忠诚义务、派生诉讼、征集投票代理权等国
为进一步深入贯彻实施《中华人民共和国行政诉讼法》,最高人民法院发布了《关于行政诉讼证据若干问题的规定》。本书即是对《行政
本书是一本引导读者深入了解Docker实现原理的技术普及读物,主要目标是通过对Docker架构和源代码的详细讲解和解剖,帮助读者对Do
《简约之美:软件设计之道》将软件设计作为一门严谨的科学,阐述了开发出优雅简洁的代码所应该遵循的基本原则。作者从为什么以前软
《有趣的二进制:软件安全与逆向分析》通过逆向工程,揭开人们熟知的软件背后的机器语言的秘密,并教给读者读懂这些二进制代码的
《StrutsHibernateSpring集成开发宝典》以Struts,Hibernate,Spring为核心详细地讲解了这三个组件的基础知识和基本使用方法,...
《朝花夕拾》内容简介:《朝花夕拾》是鲁迅重要的作品集之一,共收录《从百草园到三味书屋》《藤野先生》等散文十篇,展现了横眉冷
《被谷歌》内容简介:我们身处这样一个汹涌激荡的时代:报纸走向破产;杂志遭遇变卖;图书出版商的利润空间被狠狠挤压;广播电视
Python是一种解释型、面向对象、动态数据类型的高级程序设计语言,自20世纪90年代初诞生至今,逐渐被广泛应用于处理系统管理任务
科技发展的速度越来越快了,快得让我们有点儿要跟不上的感觉,不知道你是否有同感?《搜酷——全球智能硬件与技术精华集(全彩)
《HTML 5开发精要与实例详解》内容简介:这是一本以综合性案例为导向并辅之以精要知识点讲解的HTML 5实战教程。内容分为两大部分:
数码摄影秘技 本书特色 本书从数码摄影初学者的角度出发,避免复杂的摄影理论,运用简单易懂的图片解析,消除读者在拍摄中遇到的困惑。本书针对拍摄人物照片、儿童照片、...
在世界各个危险的海路上航行,需要可靠的设备,磁罗盘因此应运而生。磁罗盘是人类史上最重要的航海装置,本书的目的即是呈现这段
《注册会计师全国统一考试专用辅导教材:税法经典题库》内容简介:为帮助广大考生更好地理解和掌握注册会计师的考试内容,我们邀请
《LED照明驱动电源模块化设计技术》内容简介:随着LED照明技术的迅速发展和LED灯具的规模化应用,对LED驱动电源的要求也越来越高。
《千年贸易战争史:贸易冲突与大国兴衰》内容简介:贸易与冲突是构成世界历史的主要内容之一,经贸利益是世界历史上很多重大战争的
EyetrackingWebUsabilityisbasedononeofthelargeststudiesofeyetrackingusabilityinex...