Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/monkey_patches.rb
Overview
Add methods to Array so that one attribute of a class can be treated as a unique key
Instance Method Summary collapse
-
#keyfind(key) ⇒ Object
The object from the array that has the specified key value.
-
#keys ⇒ Array<Object>
An array containing the key fields from a collection of objects.
Instance Method Details
#keyfind(key) ⇒ Object
Returns The object from the array that has the specified key value.
63 64 65 66 |
# File 'lib/monkey_patches.rb', line 63 def keyfind(key) self.each { |e| return e if key == e.key } nil end |
#keys ⇒ Array<Object>
Returns An array containing the key fields from a collection of objects.
57 58 59 |
# File 'lib/monkey_patches.rb', line 57 def keys self.collect { |e| e.key } end |