Class: Ruleby::Core::ObjectPattern
- Defined in:
- lib/core/patterns.rb
Overview
This class represents a pattern that is looking for the existence of some object. It contains a list of ‘atoms’ that represent the properties of the class that we are looking for.
Direct Known Subclasses
CollectPattern, InheritsPattern, InitialFactPattern, NotPattern
Instance Attribute Summary collapse
-
#atoms ⇒ Object
readonly
Returns the value of attribute atoms.
Instance Method Summary collapse
- #==(pattern) ⇒ Object
- #head ⇒ Object
-
#initialize(head, atoms) ⇒ ObjectPattern
constructor
A new instance of ObjectPattern.
- #to_s ⇒ Object
Constructor Details
#initialize(head, atoms) ⇒ ObjectPattern
Returns a new instance of ObjectPattern.
24 25 26 |
# File 'lib/core/patterns.rb', line 24 def initialize(head, atoms) @atoms = [head] + atoms end |
Instance Attribute Details
#atoms ⇒ Object (readonly)
Returns the value of attribute atoms.
22 23 24 |
# File 'lib/core/patterns.rb', line 22 def atoms @atoms end |
Instance Method Details
#==(pattern) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/core/patterns.rb', line 32 def ==(pattern) if pattern.class == self.class atoms = pattern.atoms if(@atoms.size == atoms.size) (0..@atoms.size).each do |i| if !(@atoms[i] == atoms[i]) return false end end return true end end return false end |
#head ⇒ Object
28 29 30 |
# File 'lib/core/patterns.rb', line 28 def head @atoms[0] end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/core/patterns.rb', line 47 def to_s return '(' + @atoms.join('|') + ')' end |