class Eco::Data::Locations::NodeDiff module Selectors # Creates selector methods on `diffs` (nodes that changed) # It also creates a method with question mark that evaluates true if **any** diff matches. # @note the selector method name with a question mark should exist in the `diff_result_class` def selector(*attrs) attrs.each do |attr| meth = attr.to_sym methq = "#{meth}?".to_sym define_method meth do diffs.select(&methq) end define_method methq do diffs.any?(&methq) end end end end end