class Schedule::FilteredRuleList

Attributes

date[R]
rules[R]

Public Class Methods

new(date, rules) click to toggle source
# File lib/schedule.rb, line 33
def initialize(date, rules)
  @date, @rules = date, rules
end

Public Instance Methods

evaluate(*args) click to toggle source

This method can be used in one of two ways:

Either directly collect the results or pass a collection object, fill it in and then use that object directly rather than using the output of this method.

# Collecting the results directly

rule -> (date) { date.tuesday? } do
  "Go swimming"
end

list.evaluate # => ["Go swimming"]

# Using a collection object

rule -> (date) { date.tuesday? } do |time_frames|
  time_frames[:morning] << "Go swimming"
end

time_frames = {morning: Array.new}
list.evaluate(time_frames) # Ignore the result.
time_frames # => {morning: "Go swimming"}
# File lib/schedule.rb, line 62
def evaluate(*args)
  self.rules.map { |rule| rule.block.call(*args) }
end