Class: CLIPS::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/clips/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, actions: [], patterns: [], salience: 0, &block) ⇒ Rule

Returns a new instance of Rule.



9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



4
5
6
# File 'lib/clips/rule.rb', line 4

def actions
  @actions
end

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/clips/rule.rb', line 5

def block
  @block
end

#patternsObject (readonly)

Returns the value of attribute patterns.



6
7
8
# File 'lib/clips/rule.rb', line 6

def patterns
  @patterns
end

#salienceObject (readonly)

Returns the value of attribute salience.



7
8
9
# File 'lib/clips/rule.rb', line 7

def salience
  @salience
end

Instance Method Details

#run!(environment, *patterns) ⇒ Object

Assumes that the patterns have already been checked

Parameters:

  • environment (CLIPS)

    The thing with all of the facts

  • patterns (Array)

    The matching patterns that triggered this CLIPS::Rule



21
22
23
24
25
26
27
28
29
# 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