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
《科学的极致:漫谈人工智能》内容简介:集智俱乐部是一个从事学术研究、享受科学乐趣的探索者组成的团体,倡导以平等开放的态度、
《祛魅:天人感应、近代科学与晚清宇宙观念的嬗变》内容简介:在漫长的传统中国,国家礼制和日常生活中都不乏对天、天道以及无数人
《研究生英语学术论文写作》内容简介:本教材以任务型教学为编写原则与核心理念,将论文写作步骤与语言技能训练融为一体,使学术论
《极简办公》内容简介:本书主要面向职场新人,详细讲解Word的使用技巧,并提供配套的视频讲解,帮助职场新人快速掌握工作中所需要
《C语言程序设计》内容简介:本书对C语言做了全面、详细、系统的介绍,全书共分十二个项目,按照程序设计的知识体系,由浅入深、循
《区域(2016年第2辑/总第6辑)》内容简介:本辑内容涉及:在广阔的世界关系中阐释中国“史”的传统及其意义;讨论欧洲民族国家兴起
亚历山大·奥斯特瓦德(AlexOsterwalder)亚历山大·奥斯特瓦德博士是国际畅销书《商业模式新生代》的第一作者,充满激情的企业家
单片机实验与实践教程-(二)(第2版) 内容简介 本书为《单片机系列教程》之一,较之第1版,增删了部分内容。保留了第1版中循序渐进、汇编语言与高级语言并重、串并...
这是一本专门为网页设计师赏析和借鉴服务的实用图典。本书收集了近1000个优秀网页设计的优秀瞬间,并为每个网页标注出URL、关键词
《西南联大历史通识课》内容简介:★西南联大博物馆官方认证版 ★1937—2022,西南联大建校85周年纪念 ★大师摇篮,世界教育史上的
《淘宝天猫开店必备技能速查速用手册》内容简介:《淘宝天猫开店必备技能速查速用手册》系统、全面地介绍了在淘宝和天猫平台上开店
《光之美学》内容简介:光帮助我们感知一切事物,有光便有影。在绘画中,光影一直是一个重要的课题,可以借用明暗关系来表达,也可
《看懂世界格局的第一本书》内容简介:本书用大开大合的笔法将复杂多变的世界全景呈现出来,并从政治经济和地缘政治的角度对以上这
《汽车标志大全.德国、法国、俄罗斯篇》内容简介:汽车品牌和它的标志是一个不可分割的整体,汽车品牌对应着标志。品牌名即是可以读
1.它是Pearson、Amazon、Bames&Noble计算机畅销书!2.知名Linux专家MarkSobell编写的这本书,为系统管理员、开发人员和高级用...
随着《我++——电子自我和互联城市》(Me++:TheCyborgSelfAndTheNetworkedCity)的出版,《比特之城》(CityOfBits)和...
《LED照明产品质量认证与检测方法》内容简介:本书全面系统地介绍了LED照明产品的国内外最新标准和技术法规、LED生产质量工艺、LED
《不慌不忙,人生慢慢来》内容简介:这是一本写给都市迷茫女性的人生答案之书。当下世界变化太快,人很容易被快速变化的世界裹挟,
本书对从原如时代服饰起源的资料及其起源动机的推论,直到20世纪80年代初期世界服饰的新款式,均给予系统介绍,并从美学角度加以
《xHTML+CSS+DreamweaverCS3标准网站构建实例详解》特别适合网站美工、网站前端架构师、网页设计爱好者、Wap页面设计师作为学习W