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
《信号与系统辅导与题解(与美国MIT麻省理工本科教材配套)》是奥本海姆教授主编的、电子工业出版社引进出版的《信号与系统》(第2
Delphi管理信息系统项目方案精解(附光盘) 内容简介 管理信息系统(MIS)在软件开发领域有着很高的地位,很多企事业单位都用它来提高效率,增强竞争力。Del...
《模拟人生》内容简介:☆“真实故事计划”第二届非虚构写作大赛获奖作品集 ☆讲述艰辛与悲伤,温柔与爱意,打动万千读者的真实故事
《我国假释制度的博弈分析》内容简介:本书采用新的视角和研究方法,运用博弈论的基本原理和基本概念,探讨我国假释制度具体规定的
Composedofthreesections,thisbookpresentsthemostpopulartrainingalgorithmforneural...
《丝绸之路上的西州回鹘王朝》内容简介:公元840年,称雄蒙古高原近百年的回鹘汗国破灭。回鹘部众西迁至天山南北两麓,以吐鲁番盆地
暢銷書《如何成為頂尖設計師》是一本實用的設計師指南,對任何想設計出有意義的作品,又不想放棄自己想法的設計師來說,非常有幫
《R用户Python学习指南:数据科学方法》内容简介:掌握一门语言、一种工具已不足以应对当今的数据分析任务,本书旨在解决这一问题,
《卑鄙的圣人:曹操10》内容简介:曹操不可避免地步入暮年,统一天下的目标依旧遥遥无期。大瘟疫毁灭生灵无数、南征孙权再度无功而
《那猫那人那城》内容简介:《猎人们》之后,朱天心全新猫书 异族他类自由来去,街猫与人族相遇的城市传奇 马家辉、杨照推荐,这不
《Python 3反爬虫原理与绕过实战》内容简介:本书首先介绍了开发环境的配置,接着讨论了Web网站的构成和页面渲染、动态网页和静态网
Thishands-onguidedemonstrateshowtheflexibilityofthecommandlinecanhelpyoubecomeam...
五笔字型汉字速查一本通(双色版) 内容简介 五笔字型输入法是王永民教授发明的一种完全依照汉字字形进行编码的汉字输入方法,五笔字型发展到今天,共经历了三个版本,即...
《工业X.0》内容简介:数字化的巨轮早已扬帆远航,任何持怀疑态度的人都无力阻止,无论是民众还是商业领袖。工业企业整体构成了全球
《征服法国外籍军团的华人特种兵》内容简介:2006—2016年,吴鑫磊前往法国留学并在法国外籍军团服役。十年间,他从语言不通的新兵
《时与光》内容简介:这是一部像推理小说一样“烧脑”的科学史话。跟随书中的一个个智者,你将从古典力学走向经典体系,最终跨入理
《石门铭》内容简介:《石门铭》,又称《泰山羊祉开复石门铭》。北魏宣武帝永平二年(五〇九)立,记述了梁、秦二州刺史羊祉和左校
《注册会计师全国统一考试专用辅导教材:税法经典题库》内容简介:为帮助广大考生更好地理解和掌握注册会计师的考试内容,我们邀请
《Scala编程(第3版)》内容简介:本书由直接参与Scala开发的一线人员编写,因而对原理的解读和应用的把握更加值得信赖。本书面向具
《思想政治理论金榜书》内容简介:本书是一本由双一流大学对口专业教授、学者合作编写的考研政治辅导教材,并严格依据教育部所颁布