Ruby

29
1221 reads

March 4, 2013

Enumerator with Hash


Use your MyCollection class to process arrays such as the keys or values of Hashes. Currently the min and max methods adopt the default behaviour of performing comparisons based on numerical values.

34
1156 reads

March 4, 2013

Enumerable methods with your MyCollection objects


Enumerable methods with your MyCollection objects

30
1240 reads

March 4, 2013

include Enumerable


Here you could initialize a MyCollection object with an array, which will be stored in the instance variable, @items.

28
1300 reads

March 4, 2013

Simple For Loop


Simple For Loop

37
1255 reads

March 4, 2013

For Loop


For Loop In Ruby

27
1138 reads

March 4, 2013

compare for loops and each iterators with arrays and ranges


This example shows how both for and each can be used to iterate over the values in a range

28
1380 reads

March 4, 2013

For Each


Using For_Each

21
1194 reads

March 4, 2013

Custom Comparison


The easiest way to do this would be to define the nature of the comparison inside a block.

21
1367 reads

March 4, 2013

Enumerator


Hash is such a class.

34
1231 reads

March 4, 2013

Using Enum


The Enumerable module is already included into the Ruby Array class and it provides arrays with a number of useful methods such as include?