Sha256: c4706cf0ba872c17e81024a16f4707f57b7f1a657177e8352ac510493b5d7450

Contents?: true

Size: 729 Bytes

Versions: 5

Compression:

Stored size: 729 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Context < Dictionary
      attr_reader :parent

      def initialize(*args, **_kargs, &)
        super(args.first)
        @parent = args.second if args.second.is_a?(Dictionary)
      end

      def code_lookup!(identifier)
        code_identifier = identifier.to_code

        if code_has_key?(code_identifier).truthy?
          self
        elsif parent?
          parent.code_lookup!(code_identifier)
        else
          raise Error, "#{code_identifier} is not defined"
        end
      end

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

      def parent?
        !!parent
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
code-ruby-1.2.5 lib/code/object/context.rb
code-ruby-1.2.4 lib/code/object/context.rb
code-ruby-1.2.3 lib/code/object/context.rb
code-ruby-1.2.2 lib/code/object/context.rb
code-ruby-1.2.1 lib/code/object/context.rb