Sha256: 0713a57b6f50c3b3bb9c2a8357706ba64fe3aa9e5e80ae0af0e1bb14cbb18d7a

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require_relative 'any_value'
require_relative 'vocabulary'

module MiniKraken
  module Core
    # Representation of a MiniKraken variable.
    # It is a named slot that can be associated with one value.
    class Variable
      # @return [String] Name of the variable
      attr_reader :name

      # @param aName [String] The name of the variable
      def initialize(aName)
        @name = valid_name(aName)
      end

      def fresh?(anEnvironment)
        anEnvironment.fresh?(self)
      end

      # @param env [Environment]
      # @return [Freshness]
      def freshness(env)
        freshness = env.freshness_ref(self)
      end

      def ground?(anEnvironment)
        !fresh?(anEnvironment)
      end

      def quote(anEnvironment)
        raise StandardError, "class #{anEnvironment}" unless anEnvironment.kind_of?(Vocabulary)

        val = anEnvironment.quote_ref(self)
        val.nil? ? AnyValue.new(name, anEnvironment) : val
      end

      private

      def valid_name(aName)
        if aName.empty?
          raise StandardError, "Variable name may not be empty."
        end

        aName
      end
    end # class
  end # module
end # module

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mini_kraken-0.1.04 lib/mini_kraken/core/variable.rb
mini_kraken-0.1.03 lib/mini_kraken/core/variable.rb