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
《TensorFlow神经网络编程》内容简介:本书首先简要介绍流行的TensorFlow库,并讲解如何用它训练不同的神经网络。你将深入了解神经
作者写作本书的灵感以及作者能提供的大量翔实的信息都直接来源于作者在UMTS论坛担任主席内5年的经历。在它最为活跃的阶段,这个国
《职业院校专业群课程体系构建研究》内容简介:本书由三部分组成。第一部分是导论,介绍了职业院校专业群建设以及专业群课程体系框
《爸爸爱喜禾:你一直在和自己玩》内容简介:口碑爆棚!写给自闭症患者家庭的希望及欢笑之书! 《见字如面》深情朗读,于丹、崔永元
学习JavaScript-第二版-影印版 本书特色 “无论你是一个初学者,还是一个正在寻求一种新语言的有经验的程序设计者,我都要明确地向你推荐《学习javasc...
《唐人佚诗解读》内容简介:本书主要内容包括诗人王绩的两种文集及其佚诗,贺知章的醉与醒,元结与《箧中集》作者之佚诗,张志和《
【内容简介】本书深入浅出地介绍了Redis的5种数据类型,并通过多个实用示例展示了Redis的用法。除此之外,书中还讲述了Redis的优
《巴塞尔姆的40个故事》内容简介:★有人向沉闷的世界开枪,有人写下40个故事 ★上一分钟是卓别林,下一分钟是卡夫卡 ★所有正能量
地理空间元数据关联网络构建与应用 本书特色 在介绍相关研究背景与意义、国内外研究现状、相关理论方法的基础上,本书阐述面向关联数据的地理空间数据语义关联网络构建方...
《世界汉学(第10卷)》内容简介:《世界汉学(第10卷)》中国人民大学出版社出版。本书包括了:汉学与汉学家在德国——过时的概念?
《Z世代营销》内容简介:《Z世代营销》是Z世代之母和Z世代研究专家的扛鼎之作。通过很多采访和案例,让大家了解生于1990-2010年之间
AlistairCockburn是用例方面的一位著名专家。他是HumansandTechnology公司的资深顾问,在那里他负责帮助客户在面向对象项目上获得
ThesecondeditionofHaskell:TheCraftofFunctionalProgrammingisessentialreadingforbe...
从0起飞Office 2007公司办公易学通 本书特色 从0起飞,电脑办公应用易学通。从0起步,模块教学,实例巧配,检测所学,视频直播,超值实惠,新手地话,解惑...
《大脑功能模式(型)理论》内容简介:在主客观事物情境模式不断刺激下,基因遗传决定的大脑生理结构和特性,建构各不相同的生理结
作为互联网发展的一个新阶段,Web2.0已经走入了我们的网络生活当中。本书集Web2.0的理念分析与具体设计于一体,希望帮助读者既能
EDIUS 6.5快刀手高效剪辑技法 本书特色 edius是一款用于广播电视和影视后期制作的视频剪辑软件,它支持当前所有标清和高清格式的实时编辑,被誉为pc平台...
《发明改变生活》内容简介:在璀璨的人类文明中,各式各样的发明层出不穷,为我们的生活带来了日新月异的变化。那发明是如何改变生
《经销商激励》内容简介:结合企业痛点介绍激励经销商常用的方法,包括:经销商激励概论、返利激励、政策激励、经销商销售竞赛、限
ExcelVBA(2003/2007)高效办公实用宝典 本书特色 结合大量的实例,深入浅出地逐步介绍excel 2003/2007 vba的基础知识和中高级知识...