Class: SimCtl::List
- Inherits:
-
Array
- Object
- Array
- SimCtl::List
- Defined in:
- lib/simctl/list.rb
Instance Method Summary collapse
-
#where(filter) ⇒ Array
Filters an array of objects by a given hash.
Instance Method Details
#where(filter) ⇒ Array
Filters an array of objects by a given hash. The keys of the hash must be methods implemented by the objects. The values of the hash are compared to the values the object returns when calling the methods.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/simctl/list.rb', line 10 def where(filter) return self if filter.nil? select do |item| matches = true filter.each do |key, value| matches &= case value when Regexp item.send(key) =~ value else item.send(key) == value end end matches end end |