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
《美国的故事(套装书共7册)》内容简介:本书聚焦于美国建国前后的激情岁月。从北美殖民地的建立,到独立战争的打响,再到美国前几
TheinternationalsuccessstoryofAntwerpfashionTheSix(WalterVanBeirendonck,AnnDemeu...
《写给未来的自己(第2季)》内容简介:本书收录了2018届“北大培文杯”全国青少年英语创意写作大赛的优秀作品。“北大培文杯”全国
《考试高手》内容简介:本书完整地提供了从复习步骤、考前冲刺到考后规划等一系列实操工具和普适方法,曾帮助大量学习者一次性通过
日本、中国の文様を植物、動物、器物といった具体的な分類でまとめた解説した事典。索引付き。日本、中国の文様を植物・動物・器
每一个渴望学习C++语言的初学者都希望能够有一本全面的,实用的,同时又是生动有趣的入门书。这本入门书可以告诉这些初学者,整个
实际案例分析是一种从用户角度定义软件系统外在特征的方法。本书对这种前沿的软件开发技术提供了清晰、实用的介绍。通过诸多实例
MattRichardson:Brooklyn的一名创意技术专家和制片人。他是MAKE杂志和Makezine.com网站的撰稿人。他也是AwesomeButto...
MarkRichards是一位造诣颇深的作者和会议演讲者,他是金融服务行业的实战型SOA和企业体系结构师。除了发表大量文章之外,他还是《
《扶贫志》内容简介:本书为反映决战脱贫攻坚重大主题的长篇报告文学,作品以精准扶贫首倡地花垣县为切入点,辐射具有典型意义的扶
《商务语言学》内容简介:本书是“当代商务英语学科建设系列”之一,主要探讨商务语言学的基本概念、商务语言学的产生背景和理据、
《开国领袖毛泽东》内容简介:《开国领袖毛泽东》真实地再现了共和国开国奠基特定历史环境中领袖人物毛泽东的心路历程、行为轨迹和
云计算-(第三版) 本书特色 本书是国内销量*大、被众多高校采用的教材《云计算》的*新升级版,是中国云计算专家咨询委员会秘书长刘鹏教授团队的心血之作。在应对大数...
《人人都要会理财》内容简介:从投资理财应有的理念与心态、各类投资品的特性及如何挑选适合的投资品、如何控制风险、如何选择理财
《华为增量绩效法》内容简介:增量绩效法是华为“打胜仗”思想的演绎和延伸,是被华为实践证明的管理利器,也是被众多中小企业验证
《全国通信专业技术人员职业水平考试参考用书:通信专业综合能力(中级)》依据《全国通信专业技术人员职业水平考试大纲》要求编写。
Photoshopcs6完全自学教程中文版 本书特色 photoshop 经典畅销书全新升级国内市场**本photoshop cs6图书荣耀上市完全的功能讲解,...
《贾伯斯傅》这本贾伯斯生前唯一授权的传记,完整记载他的一生。但这本书谈的不只是贾伯斯。人人都知道贾伯斯不遗余力捍卫隐私,
《Docker从入门到实战》内容简介:本书从Docker的相关概念与基础知识讲起,结合实际应用,通过不同开发环境的实战例子,详细介绍了
计算机网络 本书特色 《计算机网络(普通高等教育计算机类特色专业系列规划教材)》(作者程莉、刘建毅、王枞)具有三个特点:**,知识结构完整,综合iso/...