How do I use the Enumerable mixin in my class?

前端 未结 2 1950
谎友^
谎友^ 2020-12-24 02:11

I have a class called Note, which includes an instance variable called time_spent. I want to be able to do something like this:

cur         


        
2条回答
  •  猫巷女王i
    2020-12-24 02:28

    The Enumerable documentations says the following:

    The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. If Enumerable#max, #min, or #sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on an ordering between members of the collection.

    This means implementing each on the collection. If you're interested in using #max, #min or #sort you should implement <=> on its members.

    See: Enumerable

提交回复
热议问题