Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Polished Ruby Programming
  • Table Of Contents Toc
Polished Ruby Programming

Polished Ruby Programming - Second Edition

By : Jeremy Evans
close
close
Polished Ruby Programming

Polished Ruby Programming

By: Jeremy Evans

Overview of this book

Most successful Ruby applications become more difficult to maintain as the codebase grows in size. Polished Ruby Programming, 2nd Edition provides you with the skills and advice you need to design Ruby programs and libraries that are robust, performant, scalable, and maintainable. The book takes you through possible implementation approaches for many common programming situations, discusses the trade-offs inherent in each approach, and explains why you may sometimes choose to use different approaches. You'll start by learning fundamental Ruby programming principles, such as correctly using core classes, class and method design, variable usage, error handling, and code formatting. Then you’ll move on to higher-level topics such as library design, metaprogramming, domain-specific languages, and refactoring. Finally, you'll learn about the pros and cons of different approaches to concurrency, what you should consider when deciding whether to use static types in your Ruby code, and how best to optimize your Ruby code. The 2nd edition of Polished Ruby Programming has been updated to include relevant changes between Ruby 3.0 and 4.0. While most principles discussed in the book apply to all recent Ruby versions, some of the content in the book is specific to Ruby 4.0, the latest release at the time of publication.
Table of Contents (20 chapters)
close
close
18
Other Books You May Enjoy
19
Index

Using exceptions to handle errors

Raising exceptions is the most common way to handle errors in Ruby. Almost all core methods in Ruby can raise an exception when called with an unexpected number of arguments:

"S".length(1)
# ArgumentError (wrong number of arguments)

The exceptions would be methods that do not require any arguments and accept an arbitrary number of arguments, such as Hash#values_at and Enumerable#chain.

In many cases, you can also get a core method to trigger an exception when passing the wrong type of argument:

'S'.count(1)
# TypeError (no implicit conversion of Integer into String)

In almost all cases, unexpected or uncommon errors should be raised as an exception, and not handled via a return value. Otherwise, you end up with a case where the error is silently ignored. In the previous section, you saw an example where the update method using a return value to signal an error can result in data loss. However, there are other cases where the results...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Polished Ruby Programming
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon