Sha256: 375215051f4668803d2dec3de828e0414d59154abcf3e8b8e4bff4762661b4ea
Contents?: true
Size: 733 Bytes
Versions: 17
Compression:
Stored size: 733 Bytes
Contents
module SimCtl class List < 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. # # @param filter [Hash] the filters that should be applied # @return [Array] the filtered array. def where(filter) return self if filter.nil? select do |item| matches = true filter.each do |key, value| case value when Regexp matches &= item.send(key) =~ value else matches &= item.send(key) == value end end matches end end end end
Version data entries
17 entries across 17 versions & 1 rubygems