Backward Compatibility in Practice with Ruby
Backward Compatibility: Practice
Welcome back! Today, we'll master what we learned about backward compatibility in practice. Get prepared to apply all the knowledge on practice tasks, but first, let's look at two examples and analyze them.
Task 1: Enhancing a Complex Data Processing Method with Default Parameters
Let's say that initially, we have a complex data processing method designed to operate on an array of hashes, applying a transformation that converts all string values within the hashes to uppercase. Here's the initial version:
We intend to expand this method, adding capabilities to filter the items based on a condition and allow for custom transformations. The aim is to retain backward compatibility while introducing these enhancements. Here's the updated approach:
In this evolved version, we've introduced two optional parameters: condition, a Proc to filter the input array based on a given condition, and transform, a Proc for custom transformations of the filtered items. The default behavior processes all items, converting string values to uppercase, which ensures that the original method's behavior is maintained for existing code paths. This robust enhancement strategy facilitates adding new features to a method with significant complexity while preserving backward compatibility, showcasing an advanced application of evolving software capabilities responsively and responsibly.
