Programming often involves repetitive tasks. Most programming languages give you some way to package common code, making it reusable across multiple applications. In this article, we’ll look at how Ruby solves the problem of code reuse in a repeatable way with Ruby Gems. We’ll also take a look at managing gem sources, giving you more options to install additional functionality libraries from various third parties.
- Ruby version – 2.1.2 or newer
Expanding Your App’s Capabilities
As your software code base grows more complex, you may find that you have to write the same code multiple times. This repetition is obviously inefficient since now any changes to that code need to occur in multiple places when you introduce a new feature or a bug fix. You can mitigate this issue by encapsulating the code into separate classes–which solves the reuse problem–but this solution only scales to a certain point. Once you start trying to add complex functionality–such as HTTP communication between different applications–you will often find yourself working in well-defined problem domains that have well-known solutions. So while it might be a good learning exercise to write your own solution to one of these problems, ultimately your application would be best served by using one of these pre-existing solutions.