Sha256: 0ccf1e49e7cb4b4cb462db7f94051d4ab9b7d420c181ddd0f1c563f09070efad

Contents?: true

Size: 690 Bytes

Versions: 25

Compression:

Stored size: 690 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Context < Dictionary
      attr_reader :parent

      def initialize(raw = {}, parent: nil)
        @raw = raw
        @parent = parent
      end

      def self.name
        "Context"
      end

      def lookup!(identifier)
        if code_has_key?(identifier).truthy?
          self
        elsif parent?
          parent.lookup!(identifier)
        else
          raise Code::Error::Undefined, "#{identifier} is not defined"
        end
      end

      def merge(other)
        Context.new(raw.merge(other.raw), parent: parent || other.parent)
      end

      def parent?
        !!parent
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
code-ruby-0.9.1 lib/code/object/context.rb
code-ruby-0.9.0 lib/code/object/context.rb
code-ruby-0.8.5 lib/code/object/context.rb
code-ruby-0.8.4 lib/code/object/context.rb
code-ruby-0.8.3 lib/code/object/context.rb
code-ruby-0.8.2 lib/code/object/context.rb
code-ruby-0.8.1 lib/code/object/context.rb
code-ruby-0.8.0 lib/code/object/context.rb
code-ruby-0.7.8 lib/code/object/context.rb
code-ruby-0.7.7 lib/code/object/context.rb
code-ruby-0.7.6 lib/code/object/context.rb
code-ruby-0.7.5 lib/code/object/context.rb
code-ruby-0.7.4 lib/code/object/context.rb
code-ruby-0.7.3 lib/code/object/context.rb
code-ruby-0.7.2 lib/code/object/context.rb
code-ruby-0.7.1 lib/code/object/context.rb
code-ruby-0.7.0 lib/code/object/context.rb
code-ruby-0.6.7 lib/code/object/context.rb
code-ruby-0.6.6 lib/code/object/context.rb
code-ruby-0.6.5 lib/code/object/context.rb