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
「openFrameworks」の世界初の解説書です。プログラミング未経験者からより強力なインタラクション開発環境を求めているProcessi
《激光熔覆再制造零件的超声检测》内容简介:本书以激光熔覆再制造零件(包含涂层及毛坯)为对象,对影响其服役性能和服役寿命的缺
关于算法分析的这多卷论著已经长期被公认为经典计算机科学的定义性描述。这一册以及刚刚出版的第4卷第2册揭开了人们急切等待的《
《绽放:第二十届新概念作文获奖者作品精选(A卷)》内容简介:本书精选2018年第20届全国新概念作文大赛一、二等奖获奖者的作品,结
《孟子讲座》内容简介:孟子是孔子之后的儒学大师,在战国中期继承孔子思想学说并把儒学发展到新的阶段,被奉为“亚圣”。本书是作
《通信原理学习辅导与考研指导》(第6版)是以樊昌信教授和曹丽娜教授编著的《通信原理》(第6版)教材为主要参考书,同时参考其他相
TheNazisdiscoveredit.TheAllieswonthewarwithit.Itconquereddiseases,changedlaws,an...
Fanswillgetbentoutofshapeiftheymissthefirstbooktocovercircuit-bending-bending,fo...
《互联网没有记忆》内容简介:写在泥板、石碑、莎草纸、手抄本上的记忆可以保存数千年。写在网络上的记忆平均存在的时长只有100天。
本书共由三章组成,第一章“网络安全篇”介绍了网络安全的概念、网络安全的问题及对策、漏洞资料。第二章“黑客揭密篇”介绍了黑
Architectslookatthousandsofbuildingsduringtheirtraining,andstudycritiquesofthose...
《爱情牛奶糖》内容简介:299道恋爱自测题,让你看清爱情的真相,为迷途羔羊指点爱情迷津,为分手达人洞悉性感内幕,告别剩女频繁的
《故宫艺术史·初民之美》内容简介:故宫学者祝勇以故宫博物院收藏的文物为依托,在那些零零散散的文物之间寻找线索,去构建中华民
本书探讨了城市化和无所不在的数字技术之间的交集,以及在这种交集中应该如何塑造我们的生活,如何引导这些历史性的力量融合,发
ParadigmsofAIProgrammingisthefirsttexttoteachadvancedCommonLisptechniquesintheco...
游戏透视 本书特色 《游戏透视(动漫游戏专业系列教材)》由浅入深、详细地讲述了绘画透视的基本概念以及不同的绘画透视种类,从动漫与游戏制作的流程出发,配合大量精美...
《社会主义核心价值观·关键词:诚信》内容简介:在一般意义上,“诚”即诚实诚恳,主要指主体真诚的内在道德品质;“信”即信用信
《Photoshop+Illustrator完美创意设计:广告特辑》作者是韩国著名的平面设计师,曾经主持设计了三星手机、韩国通信网站等众多国际
《思考+:6种力量成就更好的自己》内容简介:每天,有无数人在说“我想想”,却依然陷入简单重复中,庸庸碌碌;或者迷失在海量信息
《潮剧史话》内容简介:潮剧是以潮州方言演唱的地方戏曲剧种,属于宋元南戏的一支,诞生于古潮州,曾有潮泉调、潮腔、潮调、潮音戏