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本24开本双色彩图精致诠释,传授视觉化思考秘笈,让好玩的画图化繁为简、解决一切商业难题!★编
计算机科学概论(刘艺) 本书特色 《计算机科学概论》可作为大学本科"计算机基础"课程教材,也可供自学人员参考使用。为更好地反映*近几年计算机学科的发展现状,作者...
《通信网理论基础(修订版)》系统介绍了通信网的理论基础。全书共分为6章,分别介绍了通信网的概念和网络的基本组成,网络的业务分
二级MS Office高级应用-2016年全国计算机等级考试无纸化真考套装三合一-(全二册)-赠428元等考大礼包 本书特色 本书严格依据*新颁布的《全国计算机...
ANSYS 14完全自学一本通 本书特色 《ansys14完全自学一本通》是一本理想的自学参考书,适合广大ansys初、中级读者学习使用。既可以作为大中专院校的...
《思无邪》内容简介:钟鼓声响起,民间的乐音比黄钟大吕更轻盈灵动,更适合不受拘束的爱情、和着钟鼓声一起起舞的两个人,一如清空
《明哥聊求职》内容简介:李明编著的《明哥聊求职》旨在帮助初入职场的年轻人了解求职的方方面面,从做好面试前的准备工作到如何编
《交互设计语言:与万物对话的艺术(全两册)》内容简介:交互设计语言是一门将复杂抽象的交互逻辑,用视觉化的形式准确呈现出来的
《军事政治学研究(2015年第2辑/总第10辑)》内容简介:《军事政治学研究》是由中国人民解放军南京政治学院军事政治学研究中心创办
《职人不足道》内容简介:当大家都在谈论“职人”时,职人本人在谈什么? 近几年,在媒体的神化渲染下,匠人、职人等词处处为用,然
《三字经·百家姓·千字文》内容简介:《三字经》、《百家姓》和《千字文》三书是迄今为止完整留存下来的产生最早、使用最久、影响
自Django创建以来,各种各样的开源社区已经构建了很多Web框架,比如JavaScript社区创建的Angular.js、Ember.js和Backbone....
《巴黎卢浮宫(伟大的博物馆·少年版)》内容简介:“伟大的博物馆·少年版”系列图书以博物馆为依托,在内容编写上融合了博
媒体推荐“EverybusinessleaderIknowworriesaboutthesamething:Arewemovingfastenough?Theg...
模型制作基础手册 内容简介 本书可以作为建筑、景观建筑、室内设计以及其他相关专业的学生所使用的初级读物。其他一些人,例如,戏剧学学生、历史学家和考古学家等,也会...
《围棋围地二选一从入门到精通(级位篇)》内容简介:本书是由少儿围棋教育专家、职业五段棋手赵守洵专为围棋初学者创作。本书按照
本书是“当代最了不起的科学家作家”卡斯蒂讲述仿真学的力作。作为正在引发科学革命的计算机仿真,不是基于直接观察实验,而是基
《信息可视化的艺术》内容简介:英国皇家艺术学院信息体验系主任Kevin Walker和伦敦大学歌德史密斯学院教授Brock Craft作序推荐 《
《知书达礼》内容简介:本书为《中华传统价值观丛书》中的一种,着眼于知书达礼这一重要的价值取向,编选历代关于读书治学、修身复
《且介亭杂文》内容简介:本书是鲁迅1934年所作杂文三十六篇,1935年末经作者亲自编定,1937年7月由上海三闲书屋初版。包括《拿来主