class CLIPS::Rule

Attributes

actions[R]
block[R]
patterns[R]
salience[R]

Public Class Methods

new(*args, actions:[], patterns:[], salience:0, &block) click to toggle source
# File lib/clips/rule.rb, line 9
def initialize(*args, actions:[], patterns:[], salience:0, &block)
    @actions = [actions].flatten(1)
    @block = block
    @patterns = patterns
    @salience = salience

    @patterns.push args unless args.empty?
end

Public Instance Methods

run!(environment, *patterns) click to toggle source

Assumes that the patterns have already been checked @param [CLIPS] environment The thing with all of the facts @param [Array] patterns The matching patterns that triggered this {Rule}

# File lib/clips/rule.rb, line 21
def run!(environment, *patterns)
    if @block
        @block.call(*patterns)
    else
        self.actions.each do |action|
            environment.add(action)
        end
    end
end