class Porolog::Scope

A Porolog::Scope is a container for Porolog::Predicates. Its purpose is to allow a Ruby program to contain multiple Prolog programs without the Prolog programs interfering with each other. @author Luis Esteban @!attribute [r] name

Name of the Scope.

Attributes

name[R]

Public Class Methods

[](name) click to toggle source

Looks up a Scope by its name. @param name [Object] the name (or otherwise object) used to register a scope. @return [Porolog::Scope] the default Scope.

# File lib/porolog/scope.rb, line 53
def self.[](name)
  @@scopes[name]
end
new(name) click to toggle source

Creates a new Scope unless it already exists. @param name [Symbol, Object] the name (or otherwise object) used to register a scope. @return [Porolog::Scope] new or existing Scope.

Calls superclass method
# File lib/porolog/scope.rb, line 28
def self.new(name)
  @@scopes[name] || super
end
new(name) click to toggle source

Initializes and registers the Scope. @param name [Object] the name (or otherwise object) used to register a scope.

# File lib/porolog/scope.rb, line 34
def initialize(name)
  @name       = name
  @predicates = {}
  
  @@scopes[@name] = self
end
reset() click to toggle source

Clears all scopes and re-creates the default Scope. @return [Porolog::Scope] the default Scope.

# File lib/porolog/scope.rb, line 43
def self.reset
  @@scopes = {}
  new(:default)
end
scopes() click to toggle source

Returns the names of all registered Scopes. @return [Array<Symbol>] the names if scopes are named as Symbols (the intended case). @return [Array<Object>] the names if the names are not actually Symbols.

# File lib/porolog/scope.rb, line 60
def self.scopes
  @@scopes.keys
end

Public Instance Methods

[](name) click to toggle source

Looks up a Predicate in the Scope by its name. @param name [Object] the name (or otherwise object) used to register a scope. @return [Porolog::Predicate] the Predicate indicated by the name.

# File lib/porolog/scope.rb, line 67
def [](name)
  @predicates[name.to_sym]
end
[]=(name, predicate) click to toggle source

Assigns a Predicate to the Scope by its name. @param name [Object] the name (or otherwise object) used to register a scope. @param predicate [Porolog::Predicate] a Predicate to be assigned to the Scope. @return [Porolog::Predicate] the Predicate assigned to the Scope. @raise [NotPredicateError] when provided predicate is not actually a Predicate.

# File lib/porolog/scope.rb, line 76
def []=(name, predicate)
  raise NotPredicateError, "#{predicate.inspect} is not a Predicate" unless predicate.is_a?(Predicate)
  @predicates[name.to_sym] = predicate
end
predicates() click to toggle source

Returns the Predicates contained in the Scope. @return [Array<Porolog::Predicate>] Predicates assigned to the Scope.

# File lib/porolog/scope.rb, line 83
def predicates
  @predicates.values
end