# File lib/hiera/interpolate.rb, line 40
    def interpolate(data, scope, extra_data, context)
      if data.is_a?(String)
        # Wrapping do_interpolation in a gsub block ensures we process
        # each interpolation site in isolation using separate recursion guards.
        new_context = context.nil? ? {} : context.clone
        new_context[:recurse_guard] ||= Hiera::RecursiveGuard.new
        data.gsub(RX_INTERPOLATION) do |match|
          (interp_val, interpolate_method) = do_interpolation(match, scope, extra_data, new_context)

          if (interpolate_method == :alias_interpolate) && !interp_val.is_a?(String)
            return interp_val if data.match(RX_ONLY_INTERPOLATION)
            raise Hiera::InterpolationInvalidValue, "Cannot call alias in the string context"
          else
            interp_val
          end
        end
      else
        data
      end
    end