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
《Spring Batch批处理框架》内容简介:本书全面、系统地介绍了批处理框架Spring Batch,通过详尽的实战示例向读者展示了Spring Bat
《深度学习之TensorFlow》内容简介:本书通过96个案例,全面讲解了深度学习神经网络原理和TensorFlow的使用方法。全书共分为3篇,第
本书《设计经典译丛:设计与文化导论》介绍在国际文化、社会和经济背景下,1900年至今的现代(与后现代)设计发展历史。它探讨后现
《世间的陀螺》内容简介:韩浩月呕心沥血之作。从故乡的逃离者、批判者到回归者,以至真至诚,直面一生所爱,深沉追忆时间深处的山
《熊猫指南·风味探索》内容简介:中华文明是四大古文明中唯一延续至今的,中国人喜好美食也是世界闻名的。如此大的国家,如此丰饶
Usabilitytestinganduserexperienceresearchtypicallytakeplaceinacontrolledlabwiths...
桑原晃弥出生于日本广岛县,毕业于庆应义塾大学经济管理专业;曾任《行业报》记者、不动产公司企划、人事课长,后为自由撰稿人;
实战Gradle 本书特色 gradle 是java 软件开发中的自动化构建工具,类似于传统工具如ant 和maven。gradle 吸收或用了maven 中比...
《源自动机的道德(人文与社会译丛)》内容简介:当代大部分对德性伦理的复兴,都是朝着亚里士多德的方向前进的。斯洛特提出,亚里
《信息产业部3G移动通信培训指定教材•3G移动通信系统概述》是为了帮助读者了解和掌握第三代移动通信系统三大主流技术的相关基础知
《SEO深度解析》以SEO从业人员普遍存在的疑问、经常讨论的问题、容易被忽视的细节以及常见的错误理论为基础,对SEO行业所包含的各
《零基础学JavaWeb开发:JSP+Servlet+Sfruts+Spring+Hibernte》全面讲解JavaWeb应用开发的编程技术,并详细介绍Java...
作者阿兰·F·祖尔等的基于他们对应用科学家讲授统计与R的丰富经验,为读者献上了《R语言初学者指南》这本书。为了避免同时讲授R
《城乡一体化发展》内容简介:这是一本全方位展现苏南地区在现代化建设中城乡一体化发展成就的重要著作。在本书作者秉持客观公正的
Itsthelittlethingsthatturnagooddigitalproductintoagreatone.Withthispracticalbook...
《Spring Boot学习指南:构建云原生Java和Kotlin应用程序》内容简介:本书语言简练,既适合刚接触Spring Boot的新手学习基础知识,
Inthisfollow-uptohisbestsellingbookExperientialMarketing,BerndSchmittintroducest...
《战火中的大学:从陕北公学到人民大学的回顾》内容简介:本书作者成仿吾是新文化运动的代表、中国共产党内著名的无产阶级教育家、
《纸币史话》内容简介:本书从汉武帝时发行的“白鹿皮币”和唐宪宗时期的“飞钱”谈起,梳理了中国古代纸币历经宋、金、元、明、清
《中医就有这么牛:全国名老中医蓝青强验案集》内容简介:蓝青强先生系广西中医药大学主任医师、教授,博士研究生导师,桂派中医大