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
本书是一本关于第三代移动通信空中接口与无线工程方面的技术专著。全书内容共17章,第1章至第3章,简要地介绍了UMTS系统的技术规
《运营实战手册:带你玩转营销套路》内容简介:本书涵盖实用的互联网运营方法,是诸位作者从多年的实战中提炼出的运营心得和精华,
书围绕着动态内存自动回收的话题,介绍了垃圾收集机制,详细分析了各种算法和相关技术。本书共12章。第1章首先介绍计算机存储器管
《有趣的二进制:软件安全与逆向分析》通过逆向工程,揭开人们熟知的软件背后的机器语言的秘密,并教给读者读懂这些二进制代码的
《JSP+DreamweaverCS4+CSS+Ajax动态网站开发典型案例》介绍了综合应用DreamweaverCS4、JSP以及Ajax技术进行动态网页设计...
一个优秀的网站,通常具备丰富的内容、美观的界面效果和独特的风格,并在这几个方面能够实现和谐的统一。在多姿多彩的互联网世界
《SQL必知必会(第5版)》内容简介:SQL是使用最广泛的数据库语言,绝大多数重要的DBMS支持SQL。本书由浅入深地讲解了SQL的基本概念
《降低税负》内容简介:纳税筹划是纳税人的一项基本权利,而偷税、漏税、抗税、逃税等则是纳税人的非法应对手段。本书立足新的税收
《短视频,你玩得起吗》内容简介:本书从专业角度教你零基础制作短视频。首先,让你从各个角度深度了解短视频,只有足够了解才能够
《培训精炼:36招成就高效讲师》内容简介:本书为培训师提炼了36个课堂培训技巧,能迅速帮助培训师提升培训技能,打造高效课堂,实
《特种作战装备》内容简介:本书主要介绍各国特种作战单位使用的各式装备,包括主战武器、自卫武器、特种作战车辆、特种作战飞机、
《创业为了什么?》内容简介:本书以主播安生的视角,讲述了7个创业者的故事,并附上与创业者的对话,不仅剖析了优秀创业者的成长历
计算机网络应用入门 本书特色 本书从利用计算机和因特网收集信息、获取信息、利用信息这个角度出发,以网络技术的基础应用为目标,联系局域网的建设和因特网应用,讲述网...
《做一个清醒的现代人》内容简介:在当代中国传统文化的纵向传承与外来文化的横向互动中,在这种“纵横交错”的文化背景下,刘擎教
《大数据时代的IT架构设计》以大数据时代为背景,邀请著名企业中的一线架构师,结合工作中的实际案例展开与架构相关的讨论。《大
《DTPWORLD》隶属于日本WorksCorporationInc.。这是一家以研究和推广计算机应用与数位媒体印刷设计的专业出版社,旗下包括《CGWo
数码摄影秘技 本书特色 本书从数码摄影初学者的角度出发,避免复杂的摄影理论,运用简单易懂的图片解析,消除读者在拍摄中遇到的困惑。本书针对拍摄人物照片、儿童照片、...
《Essential C++中文版》内容简介:本书以四个面向来表现C++的本质:procedural(面向过程的)、generic(泛型的)、object-ba...
《汉英委婉语跨文化比较研究》内容简介:本专著通过跨文化交际的视角对汉英语言在职业委婉语、新闻委婉语、广告委婉语、死亡委婉语
《创新家装设计图典(第4季):客厅》内容简介:全新升级的《创新家装设计图典第4季》将继续为读者提供新的设计案例,针对居室各空