Class: Array

Inherits:
Object
  • Object
show all
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

Instance Method Details

#keyfind(key) ⇒ Object

Returns The object from the array that has the specified key value.

Parameters:

  • key (Object)

    The key value to search for

Returns:

  • (Object)

    The object from the array that has the specified key value



59
60
61
62
# File 'lib/monkey_patches.rb', line 59

def keyfind(key)
  self.each { |e| return e if key == e.key }
  nil
end

#keysArray<Object>

Returns An array containing the key fields from a collection of objects.

Returns:

  • (Array<Object>)

    An array containing the key fields from a collection of objects



53
54
55
# File 'lib/monkey_patches.rb', line 53

def keys
  self.collect { |e| e.key }
end