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
《中国私募基金投资年度报告2015》内容简介:“私募股权(PE)”、“阳光私募”(即对冲基金)和“私募房地产”,是全球资产规模最大
《北京礼俗文化》内容简介:北京礼俗文化中的诸多礼仪习俗,以及人们所说的“北京人的礼数大”,都与中华历史的发展脉络密不可分,
Pro/Engineer Wildfire3.0基础设计与实践-(含光盘) 本书特色 本书首先以机械零件的建立为例提出问题,然后结合建模理论分析问题,再通过建模...
《AdobeDreamweaverCS5中文版经典教程》由Adobe公司的专家编写,是AdobeDreamweavelCS5软件的官方指定培训教材。全书共分为1...
ArcGIS 9地理信息系统应用与实践-(上.下册) 内容简介 地理信息系统软件ArcGIS以其强大的功能体系和全方位的技术支持逐渐成为中国地理信息界用户群体*...
《拆解一切故事写作》内容简介:有人想成为人人仰慕的作家;有人想靠写作赚取收入;有人纯粹是喜欢写作;有人则想通过写作抒发内心
《狐狸踏雪的三种可能》内容简介:诗要抵达真实,诗要抵达纯粹,诗更要抵达大众。本书主打独立诗歌品牌“诗100”,收录的100首诗歌
《CAE分析大系:ABAQUS工程实例详解》内容简介:本书基于全新的机电工程实际案例,以基本理论、分析思路、标准操作流程(SOP)和结果
《微信小程序策划与运营》内容简介:本书全面介绍了微信小程序及小程序运营各模块的具体内容。第1章重点介绍小程序到底是什么,其中
《学习正则表达式》从正则表达式的基本概念讲起,到编写完整的sed和Perl脚本,再到转换HTML文件,将这种强大的工具解释得清晰透彻
《文化翻译与经典阐释(增订本)》内容简介:本书是作者的一部专题研究文集,分为上中下三编:上编“翻译的文化学反思”,首次在中
《精益企业之现场管理实战(图解版)》内容简介:随着工业4.0时代的到来,以及“中国制造2025”行动计划的不断推进,许多企业开始更
《这一生关于你的风景》内容简介:我们终其一生,都在自我发现的道路上持续行走,推翻重建,自我成全。或许这条路,一辈子都走不完
《一个女孩的恐惧》内容简介:一个深夜,女孩手持双管猎枪,径直冲进森林,用枪口抵住一个人的额头,扣下扳机 人们常常说熊镇太不起
《生命3.0》内容简介:在人工智能崛起的当下,你希望看到一个什么样的未来?当超越人类智慧的人工智能出现时,人类将何去何从?你是
《言语行为与制度社会的建构》内容简介:本书在新的语境下研究了制度社会建构的认知基础尤其是语言基础,并通过作为社会基本构成要
ControlLogix 系统实用手册 内容简介 随着计算机技术的迅猛发展,工业控制产品加快了推陈出新的步伐,可编程自动化控制器问世几年以来,已逐步发展成为操作...
本书主要讲解Windows高级调试思想和工具,并涉及一些高级调试主题。本书内容主要包括:工具简介、调试器简介、调试器揭密、符号文
作者简介ZuradaistheS.T.FifeAlumniProfessorofElectricalEngineeringattheUniversityofLo...
《中国人力资源法律审计报告2018——从东盟十国看“一带一路”国家的劳动与雇佣管制》内容简介:本报告是“中国人力资源审计系列报