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
《零基础学算法 第3版》内容简介:本书分为上、下两篇,共10章。上篇用5章的篇幅介绍了算法和数据结构的基础知识,包括基础算法思想
《青春红楼:红楼梦整本书阅读》内容简介:在《红楼梦》被纳入高考必读书目,以及“整本书阅读”被不断强调的当下,本书作者作为一
《不插电的计算机科学》主要内容简介:“ComputerSciericeUnplugged”(不插电的计算机科学)是面向世界范围的信息科学普及项目,
Pro/ENGINEER Wildfire3.0工程图制作1CD 内容简介 本书在循序渐进的教学中,通过精选的案例讲解了Pro/ENGINEER Wildfir...
《梭罗密码》内容简介:《梭罗密码》是少年原野科幻探险系列的第六部,前四部《原野时空》《宝石幻镜》《怪物危机》《时间猎人》已
《世界大学排名与中国高水平大学建设》内容简介:世界大学排名主要通过加工处理各大学间的可比信息,以简单直观的结果反映各高校办
Learnhowtowriteidiomatic,effectivePythoncodebyleveragingitsbestfeatures.Pythonss...
《世界航空发动机手册》共分为4个部分。主体部分有:涡轮风扇发动机、涡轮喷气发动机、涡轮轴/涡轮螺旋桨发动机、桨扇发动机、活
Whatcancomputersdoinprinciple?Whataretheirinherenttheoreticallimitations?Thesear...
《超级面试官》内容简介:面试是人才招聘过程中的重要一环,面试官的水平直接影响到所招人员的素质高低。那么,面试官该具备哪些基
网络英语-(中英双语) 本书特色 优秀的网上冲浪者没有固定的交流模式,如何在不同情景下选择*佳的交流方式呢 通过情景交流提升网上冲浪技能,通过案例分析提高各种在...
《数学战略家:谷超豪传》内容简介:《谷超豪传(数学战略家)》是《大家丛书》系列丛书之一。谷超豪,数学家。复旦大学教授,中国科
《马云商道真经》内容简介:《马云商道真经》从马云对人生的认识、以及他超出常人的"狂妄",创业精神、团队合作、经营理念、企业管
《世风日上》内容简介:雪球创始人方三文和聪明投资者“聊”出来的智慧。关于炒股通过炒股实现财务自由,既是立身,也是立业,又是
《Ajax实战实例详解》堪称Ajax领域内的典范之作,深受读者好评。它以Ajax的简要介绍开篇,然后以知识点为脉络,讲述了几十个易于
嵌入式系统原理及接口技术高职 内容简介 近年来,国内教学科研单位使用的教学实验开发平台,基于s3c2410a微处理器的较为广泛,在产品开发中也较为常用。本书系统...
《像绣花一样精细:城市治理的金山实践》内容简介:本书由上海交通大学中国城市治理研究院与上海市金山区合作编写。以案例的形式展
◎這是一本專為您個人及企業打造的工具書您是否正在不斷地尋求組織創新思考的方法?打造顧客整體消費體驗的方式?技術創新應用的
《原力:再造企业价值战略》内容简介:在移动互联背景下,商业环境发生了巨大变化,新商业模式正在井喷,巨大的价值潜力不断释放。
CreativeBootCampisa30-daycreativetrainingprogramthatwillincreasethequantityandqu...