Interfaces are named collections of method signatures. In Ruby, we use modules to define interfaces, although they are not strictly enforced like in some other languages.
To run the program:
In Ruby, we use modules to define interfaces. While Ruby doesn’t enforce interface implementation as strictly as some other languages, it’s a common practice to raise a NotImplementedError for methods that should be implemented by including classes.
The include keyword in Ruby is used to add methods from a module to a class, which is similar to implementing an interface in other languages.
Ruby’s dynamic nature allows for duck typing, which means that as long as an object responds to the methods called on it, it can be used regardless of its type. This is why we can pass both Rect and Circle instances to the measure method without explicitly declaring that they implement a specific interface.
To learn more about Ruby’s modules and how they can be used to create interfaces, check out the Ruby documentation on modules.