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
《猫派》内容简介:◆十二则刊载于《纽约客》杂志的“现象级”短篇小说 ◆网络上超三百万人次转发,HBO即将改编影视 ◆人的情感,真
《知识图谱技术与应用》内容简介:本书系统地介绍了知识图谱的相关概念、技术要素与应用,不仅涵盖了知识图谱技术的发展历程与特点
《任正非与华为神话》内容简介:华为作为中国最伟大的企业,成立于1987年,目前拥有超过18万名员工,业务遍及170多个国家和地区,年
《嗨,夏威夷(图文版)》内容简介:夏威夷是人间的净土、浪漫的天堂、激情的乐园,也是冒险者与探险者的炼狱场。你可以试身火海,
《谈龙录 石洲诗话》内容简介:赵执信《谈龙录》一卷,该书主要为反对王士禛“神韵说”而作,主张“诗以言志”,必使后世因其诗以知
《汽车发动机试验学教程》是对现代汽车发动机试验进行全面系统论述的专业教科书。书中首先论述了进行汽车发动机试验必备的试验台
2006上半年试题分析与解答察团(软考) 内容简介 本书是针对全国计算机技术与软件专业技术资格(水平)考试而编写的,书中详尽分析与解答了2006年上半年的程序员...
Essential C++:英文版 本书特色 本书是众多C++初学者的入门经典。全书从4个方面来表现C++的本质:procedural(过程化的)、generi...
SQL语法简洁,使用方式灵活,功能强大,已经成为当今程序员不可或缺的技能。本书是深受世界各地读者欢迎的SQL经典畅销书,内容丰
《紫式部日记》内容简介:《紫式部日记》囊括平安时代宫廷女性经典日记文学作品《蜻蛉日记》《和泉式部日记》《紫式部日记》《更级
《详解AutoCAD 2022机械设计(第6版)》内容简介:本书结合典型机械设计案例,详细讲解AutoCAD 2022机械设计的知识要点,让读者在学
《HTMLCSSJavaScript网页制作从入门到精通》共分为18章和4个附录,重点介绍使用HTML进行网页制作的方方面面,同时讲解了目前流行
《乾坤衍》内容简介:熊十力哲学三部曲:《新唯识论》《体用论》《乾坤衍》。从中可以清晰看到熊十力思想的出发点和演变轨迹。熊十
《Flash网站建设技术精粹》并不是一本大而全的图书,而是以Flash网站技术要点为主、注重实用性的一本图书。《Flash网站建设技术精
Ifyouknowhowtoprogram,youhavetheskillstoturndataintoknowledgeusingthetoolsofprob...
《德国设计图典》是艺术设计专业的入门参考书,旨在通过简单的百科式构架和丰富直观的图片资料来帮助初学者接触、理解和掌握德国
《美国陆军图鉴(下册)》内容简介:美国陆军是一支具备全球部署及作战能力的地面军事力量。本书以彩图图解的方式,系统介绍了美国
《帆船、海盗与世界》内容简介:轮子、马镫、弓箭、火药和帆船,在历史的时间线上,每一个器物都有它值得诉说的故事,它们引发国家
《清华少年说(第四辑)》内容简介:这是一本关于清华年青学子的书籍。无论是醉心学术、勤奋有加的学霸,还是矢志不渝、情系家国的
知识就是力量,信息就是能量,数据就是变量。本书全面阐述了人类从IT时代走向DT时代的基本特征和规律。《DT时代》认为,大数据正