# frozen_string_literal: true

module Liquid
  class StaticRegisters
    attr_reader :static

    def initialize(registers = {})
      @static    = registers.is_a?(StaticRegisters) ? registers.static : registers
      @registers = {}
    end

    def []=(key, value)
      @registers[key] = value
    end

    def [](key)
      if @registers.key?(key)
        @registers[key]
      else
        @static[key]
      end
    end

    def delete(key)
      @registers.delete(key)
    end

    UNDEFINED = Object.new

    def fetch(key, default = UNDEFINED, &block)
      if @registers.key?(key)
        @registers.fetch(key)
      elsif default != UNDEFINED
        @static.fetch(key, default, &block)
      else
        @static.fetch(key, &block)
      end
    end

    def key?(key)
      @registers.key?(key) || @static.key?(key)
    end
  end
end

# frozen_string_literal: true

module Liquid
  class StaticRegisters
    attr_reader :static

    def initialize(registers = {})
      @static    = registers.is_a?(StaticRegisters) ? registers.static : registers
      @registers = {}
    end

    def []=(key, value)
      @registers[key] = value
    end

    def [](key)
      if @registers.key?(key)
        @registers[key]
      else
        @static[key]
      end
    end

    def delete(key)
      @registers.delete(key)
    end

    UNDEFINED = Object.new

    def fetch(key, default = UNDEFINED, &block)
      if @registers.key?(key)
        @registers.fetch(key)
      elsif default != UNDEFINED
        if block_given?
          @static.fetch(key, &block)
        else
          @static.fetch(key, default)
        end
      else
        @static.fetch(key, &block)
      end
    end

    def key?(key)
      @registers.key?(key) || @static.key?(key)
    end
  end
end

Fix warning about block and default value
Fix warning about block and default value

Ruby's Array#fetch accepts either a default value or a block, but not
both. If both are passed in, then it uses the block and outputs this
warning:

```
lib/liquid/static_registers.rb:34: warning: block supersedes default value argument
```
