Class: OMF::Rete::Planner::PlanSet

Inherits:
Object
  • Object
show all
Defined in:
lib/omf_rete/planner/plan_set.rb

Overview

hash of an object to determine identity.

Instance Method Summary collapse

Constructor Details

#initializePlanSet

Returns a new instance of PlanSet.



14
15
16
17
# File 'lib/omf_rete/planner/plan_set.rb', line 14

def initialize()
  @hash = {}
  @plans = []
end

Instance Method Details

#==(set) ⇒ Object

Returns true if two sets are equal. The equality of each couple of elements is defined according to Object#eql?.



35
36
37
38
39
40
41
42
# File 'lib/omf_rete/planner/plan_set.rb', line 35

def ==(set)
  equal?(set) and return true
    
  set.is_a?(PlanSet) && size == set.size or return false
    
  hash = @hash.dup
  set.all? { |o| hash.include?(o) }
end

#add(o) ⇒ Object Also known as: <<

Adds the given object to the set and returns false if object is already in the set, true otherwise.



66
67
68
69
70
71
72
73
74
75
# File 'lib/omf_rete/planner/plan_set.rb', line 66

def add(o)
  really_added = false
  oh = o.hash
  unless @hash.key?(oh)
    really_added = true
    @hash[oh] = o
    @plans << o
  end
  really_added 
end

#eachObject

Calls the given block once for each element in the set, passing the element as parameter. Returns an enumerator if no block is given.



57
58
59
60
61
# File 'lib/omf_rete/planner/plan_set.rb', line 57

def each
  block_given? or return enum_for(__method__)
  @plans.each do |o| yield(o) end
  self
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/omf_rete/planner/plan_set.rb', line 24

def empty?
  @plans.empty?
end

#eql?(o) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/omf_rete/planner/plan_set.rb', line 44

def eql?(o) # :nodoc:
  return false unless o.is_a?(PlanSet)
  @plans.eql?(o.instance_eval{@plans})
end

#include?(o) ⇒ Boolean

Returns true if the set contains the given object.

Returns:

  • (Boolean)


50
51
52
# File 'lib/omf_rete/planner/plan_set.rb', line 50

def include?(o)
  @hash.has_value?(o)
end

#lengthObject



28
29
30
# File 'lib/omf_rete/planner/plan_set.rb', line 28

def length
  @plans.length
end

#to_aObject

Converts the set to an array. The order of elements is uncertain.



20
21
22
# File 'lib/omf_rete/planner/plan_set.rb', line 20

def to_a
  @plans
end