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
本书以超宽带冲激无线电(UltraWidebandImpulseRdio)为重点,系统阐述超宽带无线通信的基本原理和技术,内容包括超宽带无线通信
高性能Linux服务器构建实战-系统安全.故障排查.自动化运维与集群架构 本书特色 畅销书《高性能Linux服务器构建实战:运维监控、性能调优与集群应用》姊妹篇...
The Adobe Illustrator CS6/CC WOW! Book 本书特色 本书共8章,第1章为您介绍创造性的工作区,主要讲解工作区的组织与软件的基...
Visual Basic程序设计基础 本书特色 《高等学校“十二五”公共课计算机规划教材:Visual Basic程序设计基础》可作为普通高等学校非计算机专业本...
《供应链商业信用协调机制研究》内容简介:本书从供应链管理的视角重点研究了商业信用对供应链协调的影响,分析了给定商业信用及其
《基础生物科学》是为大学本科学生编写的教材,适用于非生物专业公共课和包括农、林、医、生物科学与生物技术、生物工程等生物类
本书是一本从头至尾都使用现实世界例子讲述有关编写Web应用程序的书籍。WebWork所强调的内容是:利用框架实现你的项目,而不是被
由鲍卫兵主编的《通信原理》由几所高校中长期从事教学实践的教师联合编写,内容全面、难度适中、分析由浅入深,论理清晰,逻辑性
《信息场的开拓:未来后信息社会交互设计》针对当前世界范围内有关交互设计和信息设计的各种疑问,通过对于信息、信息设汁以及与当
Ifyoureawebsitedesigner,intranetmanagerorsomeonewithoutmuchInformationArchitectu...
《大型IT系统性能测试入门经典》内容简介:《大型IT系统性能测试入门经典》是一本来自性能测试实战领域的专家作品,主要用来指导性
程序员增值合订本2002 本书特色 全套合订本适合开发者、项目经理 CTO&CIO、编程爱好者阅读收藏内含:精装大16开上、下两册,52个印张,832页,另附配...
《故宫艺术史·初民之美》内容简介:故宫学者祝勇以故宫博物院收藏的文物为依托,在那些零零散散的文物之间寻找线索,去构建中华民
2009-黑客防线-(精华奉献本)(全2册)(附2张光盘) 本书特色 透视黑客技术发展焦点,把握黑客攻防技术跳动脉搏,全面收录流行黑客技术黑客编程实战大演练,黑...
尼可拉斯.卡爾(NicholasG.Carr)知名作家兼思想家,專研商業策略、資訊科技及兩者的交叉點,在《哈佛商業評論》寫過包括〈IT沒有
《数据库系统实现(第2版)》是斯坦福大学计算机科学专业数据库系列课程第二门课的教科书。书中对数据库系统实现原理进行了深入阐述
qmailhasquietlybecomeoneofthemostwidelyusedapplicationsontheInternettoday.Itspow...
《虚拟人》内容简介:人类躯体死亡,思维是否有可能继续存在,从而实现思维不朽?思维克隆人、网络人等虚拟人将如何颠覆人类对“我
《DSP原理及其C编程开发技术》可作为电子、通信、自动化及计算机工程专业高年级本科生或研究生学习DSP的教材,也可作为专业工程技
《视界·无界2.0:写给UI设计师的设计书(全彩)》内容简介:作为一名从事设计职业的设计师,或者正在通往成为设计师道路的朋友,都