Digging Deeper Hashes, Arrays, Ranges and Sets all include a Ruby module called Enumerable. A module is a sort of code library (I’ll have more to say about modules in Chap-ter 12). In Chapter 4, I used the Comparable module to add comparison methods such as < and > to an array. You may recall that I did this by subclassing the Array class and ‘including’ the Comparable module into the subclass: class Array2 < Array include Comparable end
|
请发表评论