Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Introduction
Ruby meets the real world
Confident code
A good story, poorly told
Code as narrative
The four parts of a method
How this book is structured
3.times { rejoice! }
Performing Work
Sending a strong message
Importing purchase records
Identifying the messages
Identifying the roles
Avoiding the MacGyver method
Letting language be constrained by the system
Talk like a duck
Herding ducks
Collecting Input
Introduction to collecting input
Indirect inputs
From Roles to Objects
Guard the borders, not the hinterlands
Use built-in conversion protocols
Indications
Synopsis
Rationale
Example: Announcing winners
Example: ConfigFile
A list of standard conversion methods
Explicit and implicit conversions
If you know what you want, ask for it
Conclusion
Conditionally call conversion methods
Indications
Synopsis
Rationale
Example: opening files
Violating duck typing, just this once
Conclusion
Define your own conversion protocols
Indications
Synopsis
Rationale
Example: Accepting either a Point or a pair
Conclusion
Define conversions to user-defined types
Indications
Synopsis
Rationale
Example: Converting feet to meters
Conclusion
Use built-in conversion functions
Indications
Synopsis
Rationale
Example: Pretty-printing numbers
Hash.[]
Conclusion
Use the Array() conversion function to array-ify inputs
Indications
Synopsis
Rationale
Example: Accepting one or many arguments
Conclusion
Define conversion functions
Indications
Synopsis
Rationale
Example: A conversion function for 2D points
About module_function
Combining conversion protocols and conversion functions
Lambdas as case conditions
Conclusion
Replace "string typing" with classes
Indications
Synopsis
Rationale
Example: Traffic light states
Conclusion
Wrap collaborators in Adapters
Indications
Synopsis
Rationale
Example: Logging to IRC
Conclusion
Use transparent adapters to gradually introduce abstraction
Indications
Synopsis
Rationale
Example: Logging to IRC, again
Conclusion
Reject unworkable values with preconditions
Indications
Synopsis
Rationale
Example: Employee hire dates
Executable documentation
Conclusion
Use #fetch to assert the presence of Hash keys
Indications
Synopsis
Rationale
Example: A wrapper for useradd(8)
Go #fetch
Customizing #fetch
Conclusion
Use #fetch for defaults
Indications
Synopsis
Rationale
Example: Optionally receiving a logger
Reusable #fetch blocks
Two-argument #fetch
Conclusion
Document assumptions with assertions
Indications
Synopsis
Rationale
Example: Importing bank transactions
Conclusion
Handle special cases with a Guard Clause
Indications
Synopsis
Rationale
Example: Adding a "quiet mode" flag
Put the return first
Conclusion
Represent special cases as objects
Indications
Synopsis
Rationale
Example: A guest user
Representing current user as a special case object
Making the change incrementally
Keeping the special case synchronized
Conclusion
Represent do-nothing cases as null objects
Indications
Synopsis
Rationale
Generic Null Object
Crossing the event horizon
Making Null Objects false-y.
Conclusion
Substitute a benign value for nil
Indications
Synopsis
Rationale
Example: Displaying member location data
If you're benign, you'll be fine!
Conclusion
Use symbols as placeholder objects
Indications
Synopsis
Rationale
Example: Optionally authenticating with a web service
The trouble with nil
Symbolic placeholders
Conclusion
Bundle arguments into parameter objects
Indications
Synopsis
Rationale
Parameter Object review
Adding optional parameters
Conclusion
Yield a parameter builder object
Indications
Synopsis
Rationale
Example: a convenience API for drawing points
Net/HTTP vs. Faraday
Yielding a builder
Conclusion
Receive policies instead of data
Indications
Synopsis
Rationale
Example: Deleting files
Conclusion
Delivering Results
Write total functions
Indications
Synopsis
Rationale
Example: Searching a list of words
Conclusion
Call back instead of returning
Indications
Synopsis
Rationale
Example
Conclusion
Represent failure with a benign value
Indications
Synopsis
Rationale
Example: Rendering tweets in a sidebar
Conclusion
Represent failure with a special case object
Indications
Synopsis
Rationale
Example: A guest user
Conclusion
Return a status object
Indications
Synopsis
Rationale
Example: Reporting the outcome of an import
Conclusion
Yield a status object
Indications
Synopsis
Rationale
Example: Yielding the outcome of an import
Testing a yielded status object
Conclusion
Signal early termination with throw
Indications
Synopsis
Example: Ending HTML parsing part way through a document
Conclusion
Handling Failure
Prefer top-level rescue clause
Indications
Synopsis
Rationale
Example
Conclusion
Use checked methods for risky operations
Indications
Synopsis
Rationale
Example
Onward to Adapters
Conclusion
Use bouncer methods
Indications
Synopsis
Rationale
Example: Checking for child process status
Conclusion
Refactoring for Confidence
MetricFu
Location
HotspotAnalyzedProblems
Ranking
Stringer
Parting Words
← Prev
Back
Next →
← Prev
Back
Next →