-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
The purpose of this book is to teach useful principles for intermediate to advanced Ruby programmers to follow. The focus is not generally on how to implement solutions, but on different implementation approaches, the trade-offs between them, and why some approaches are better in certain situations. While the main focus of the book is teaching principles, in some cases this book also teaches advanced Ruby programming techniques.
This book starts by teaching some fundamental principles, such as how best to use the core classes, when and how best to use each variable type, and how best to use the different types of method arguments. After building on the fundamental principles, the book teaches principles for better library design, such as how best to design extensible plugin systems, trade-offs when using metaprogramming and DSLs, and how best to approach testing, refactoring, concurrency, static typing, and optimization.
The target audience for the book is intermediate to advanced Ruby programmers who are interested in learning principles to improve their Ruby programming.
Chapter 1, Getting the Most out of Core Classes, focuses on the optimal usage of the built-in classes.
Chapter 2, Designing Useful Classes, focuses on when it makes sense to implement a class, applying SOLID design to classes, and the trade-offs between having large classes and having a large number of classes.
Chapter 3, Proper Variable Usage, focuses on how best to use each of Ruby's variable types.
Chapter 4, Methods and Their Parameters, focuses on method naming principles, the best usage of each of the method argument types, and choosing proper method visibility.
Chapter 5, Handling Errors, focuses on the trade-offs between using exceptions and return values for handling errors, handling transient errors, and designing exception class hierarchies.
Chapter 6, Formatting Code for Easy Reading, focuses on different viewpoints on the importance of syntactic complexity and the downsides of arbitrary limits.
Chapter 7, Designing Your Library, focuses on designing your library around the user experience and complexity trade-offs when designing methods for your library.
Chapter 8, Designing for Extensibility, focuses on designing useful plugin systems to allow for extensibility in libraries.
Chapter 9, Metaprogramming and When to Use It, focuses on the pros and cons of abstraction, avoiding redundancy, and trade-offs between the two approaches Ruby has for metaprogramming.
Chapter 10, Designing Useful Domain-Specific Languages, focuses on when and how best to design DSLs.
Chapter 11, Testing to Ensure Your Code Works, focuses on why testing is so important, how to approach testing and manage complexity during testing, and the importance of code coverage.
Chapter 12, Handling Change, focuses on when and how best to implement refactoring in libraries, and deprecation strategies.
Chapter 13, Using Common Design Patterns, focuses on principles for the best usage of five common design patterns.
Chapter 14, Choosing Your Concurrency Approach, focuses on different concurrency approaches in Ruby and their trade-offs, how to approach CPU-bound and IO-bound applications, and making code ractor compatible.
Chapter 15, Static or Duck, focuses on what static typing means in Ruby, the trade-offs involved in statically typing Ruby code, and whether it makes sense to use static types in your code.
Chapter 16, Optimizing Your Code, focuses on determining when optimization is needed and how to approach optimization if it is needed.
This book assumes intermediate to advanced knowledge of the Ruby programming language. There are sections of the book that are accessible to those with only basic knowledge of Ruby, but most of the book assumes you already understand how Ruby works and tries to teach principles for more productive usage of Ruby.
While most of the ideas and principles discussed in the book, and most of the code examples used in the book, apply to any version of Ruby, some of the examples and principles are specific to Ruby 4.0, the latest release at the time of publication.
If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Polished-Ruby-Programming-2nd-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "There are a few cases where you will want to return true or false and not other objects."
A block of code is set as follows:
class Foo
def self.bar = :baz
end
Any command-line input or output is written as follows:
# Warming up --------------------------------------
# MultiplyProf 72.655k i/100ms
# Calculating -------------------------------------
# MultiplyProf 738.559k (_ 0.8%) i/s
The reason for the # in the command-line input or output sections is that all code blocks in this book must be valid Ruby code (sometimes heredocs are used instead of #).
Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: " There are many good options for profiling Ruby code, from older profilers such as ruby-prof and stackprof, to newer profilers such as Vernier and rbspy."
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at [email protected] and mention the book's title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packt.com/.
Once you've read Polished Ruby Programming, Second Edition, we'd love to hear your thoughts! Scan the QR code below to go straight to the Amazon review page for this book and share your feedback.

https://packt.link/r/1803243643
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.
Change the font size
Change margin width
Change background colour