Class: CLIPS::Rule
- Inherits:
-
Object
- Object
- CLIPS::Rule
- Defined in:
- lib/clips/rule.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#salience ⇒ Object
readonly
Returns the value of attribute salience.
Instance Method Summary collapse
-
#initialize(*args, actions: [], patterns: [], salience: 0, &block) ⇒ Rule
constructor
A new instance of Rule.
-
#run!(environment, *patterns) ⇒ Object
Assumes that the patterns have already been checked.
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
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
4 5 6 |
# File 'lib/clips/rule.rb', line 4 def actions @actions end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/clips/rule.rb', line 5 def block @block end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
6 7 8 |
# File 'lib/clips/rule.rb', line 6 def patterns @patterns end |
#salience ⇒ Object (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
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 |