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
本书是数字通信领域的一本经典教材,通过对概率论及随机过程的复习,详细介绍了数字和模拟信源编码、数字调制信号和窄带信号与系
《全球化视野中的青年文化》内容简介:促进青年文化健康发展,对整体社会的发展具有重要意义。本书选择全球化视野下的青年文化作为
人因学作为一门新兴的学科,在当今工业设计领域越来越受重视,这本《人因工程学导论》的主要意图是对人因学原理进行清楚直观的说
《爱上一座城》内容简介:每个人都有属于自己的城市印记,无论是出生的家乡,还是为了工作奋斗的城市,抑或是想要安度一生的土地。
《老子永远不老》内容简介:本书收入了12篇曹峰近年来发表的《老子》及道家研究论文,约二十万字。其中有对具体章节如三十六章、三
《世风日上》内容简介:雪球创始人方三文和聪明投资者“聊”出来的智慧。关于炒股通过炒股实现财务自由,既是立身,也是立业,又是
《先秦儒学核心范畴英译研究》内容简介:本书将思想史研究与中西文化哲学比较纳入先秦儒学核心文化范畴可译性研究。以先秦儒学思想
深度学习-基于MATLAB的设计实例 本书特色 深度学习如此流行,以至于关于它的资料随处可见。但往往是理论连篇,并不适合开发者具体使用,本书内容丰富实用、原理直...
《笨拙的教养》内容简介:这是一场面向未来的教养之旅。作者以国际化视野、多元化视角深入体察、审视中西方教育观念及现状的不同。
《国企混改:理论、模式与路径》内容简介:国企改革始终是中国经济体制改革的中心环节和核心内容,以所有制混合为特征的新一轮国企
《西方左翼学者的马克思主义观》内容简介:本书主要反映西方左翼学者(其中既包括西方马克思主义和后马克思主义思潮与流派的代表人
《TensorFlow机器学习(原书第2版)》内容简介:本书是升级版,不仅包含机器学习的基本概念,以及如何利用TensorFlow库快速构建强大
《光纤通信(第2版)》内容涉及光纤通信领域的多个方面,具体包括传输光纤、半导体光源和光检测器、无源光器件、光放大器、光纤通信
《光明,那一页(精)》内容简介:本书为“四个一批”人才、光明日报社江苏记者站站长郑晋鸣的作品集。全书共收入郑晋鸣1998年以来
《颜真卿颜家庙碑(上)——中华碑帖精粹》内容简介:《颜氏家庙碑》全称《唐故通议大夫行薛王友柱国赠秘书少监国子祭酒太子少保颜
《国学研究(第46卷)》内容简介:本书为袁行霈先生主编、北京大学国学研究院主办之辑刊,每年两卷,此为第46卷。本期共收录相关领
《走!去博物馆学历史·中国国宝篇》内容简介:《走!去博物馆学历史》共2册——中国国宝篇、世界国宝篇,每册共10章,介绍了13个博
随着宽带业务需求的发展和潜在的巨额利润,宽带城域网正成为当前建设的热点。《宽带城域网实用手册》从内容的实用性和技术的先进
Recentyearshaveseenthedevelopmentofpowerfultoolsforverifyinghardwareandsoftwares...
《丝绸之路上的西州回鹘王朝》内容简介:公元840年,称雄蒙古高原近百年的回鹘汗国破灭。回鹘部众西迁至天山南北两麓,以吐鲁番盆地