Sha256: e92886196c7b403e535048c0bc926a9b1e80578984191616c6664e575cb180d6

Contents?: true

Size: 754 Bytes

Versions: 26

Compression:

Stored size: 754 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Context < Dictionary
      attr_reader :parent

      def initialize(*args, **_kargs, &_block)
        raw = args.first || Dictionary.new
        raw = raw.raw if raw.is_a?(Object)
        @raw = raw.to_h
        @parent = Context.new(args.second) if args.second
      end

      def lookup!(identifier)
        if code_has_key?(identifier).truthy?
          self
        elsif parent?
          parent.lookup!(identifier)
        else
          raise Error::Undefined, "#{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

26 entries across 26 versions & 1 rubygems

Version Path
code-ruby-1.0.0 lib/code/object/context.rb
code-ruby-0.15.16 lib/code/object/context.rb
code-ruby-0.15.15 lib/code/object/context.rb
code-ruby-0.15.14 lib/code/object/context.rb
code-ruby-0.15.13 lib/code/object/context.rb
code-ruby-0.15.12 lib/code/object/context.rb
code-ruby-0.15.11 lib/code/object/context.rb
code-ruby-0.15.10 lib/code/object/context.rb
code-ruby-0.15.9 lib/code/object/context.rb
code-ruby-0.15.8 lib/code/object/context.rb
code-ruby-0.15.7 lib/code/object/context.rb
code-ruby-0.15.6 lib/code/object/context.rb
code-ruby-0.15.5 lib/code/object/context.rb
code-ruby-0.15.4 lib/code/object/context.rb
code-ruby-0.15.3 lib/code/object/context.rb
code-ruby-0.15.2 lib/code/object/context.rb
code-ruby-0.15.0 lib/code/object/context.rb
code-ruby-0.14.9 lib/code/object/context.rb
code-ruby-0.14.8 lib/code/object/context.rb
code-ruby-0.14.6 lib/code/object/context.rb