It is the exact same idea: you have a family of functions indexed by the domain of the functions, and you use this fact to construct a function not in the initial family.
(Aside: I really wish authors would stop proving Cantor's Theorem and variants by "contradiction"; it's really a contrapositive proof that has been converted to a "proof by contradiction" by adding the contrary assumption at the top, and then parading it at the end to claim the desired contradiction; just do a contrapositive proof!).
That is, it is an instance of the following argument:
Diagonal Argument. Let $S$ be a nonempty set, and let $X$ be a set with at least two elements. Let $\{f_s\}_{s\in S}$ be a family indexed by $S$, where each $f_s$ is a function $f_s\colon S\to X$ with domain $S$ and codomain $X$. Then there exists a function $g\colon S\to X$ such that $g\neq f_s$ for all $s\in S$.
Proof. Since $X$ has at least two elements, let $a,b\in X$, with $a\neq b$. Define $g$ as follows: given $s\in S$, we let
$$g(s) = \left\{\begin{array}{ll}
a & \text{if }f_s(s) \neq a;\\
b & \text{if }f_s(s)=a.
\end{array}\right.$$
This is a function with domain $S$ and codomain $X$. To show that $g\neq f_s$ for each $s\in S$, let $s_0\in S$. Then $g(s_0) \neq f_{s_0}(s_0)$ by construction. Since two functions $S\to X$ are equal if and only if they take the same value at each and every element of $S$, and $g$ and $f_{s_0}$ take different values at $s_0$, it follows that $g\neq f_{s_0}$, as claimed.
Thus, $g$ is a function from $S\to X$ that is not in our original collection. $\Box$
(Why is it called the "Diagonal Argument"? Because if you imagine your functions as being in a square "table", where the rows and columns are labeled by elements of $s$, with each row describing the values of a function, so that the entry in row $i$ and column $j$ is the value of the $i$th function at $j$, $f_i(j)$, then we are constructing $g$ by looking at the values at the "diagonal" of the table, the entries $(s,s)$.)
This argument is the engine of the proof of Cantor's Theorem (no set can be put in bijective correspondence with its power set), Cantor's second proof of uncountability of the real numbers, and the result you quote.
(I use $a$ and $b$ so I don't have to worry about the Axiom of Choice, which is likely not on your radar; but all you need is a method by which you can take the value $f_s(s)$, and get something different. If your values are taken in $\mathbb{N}$, or in $\mathbb{R}$, you can just "add one", and that will do. All you need is a way to take the value $f_s(s)$, and find some different value in $X$.)
To see this explicitly, let's look at those arguments:
1. Cantor's Theorem. Let $S$ be a set. Then there is no bijection between $S$ and its power set $P(S)$. Explicitly, if $F\colon S\to P(S)$ is any function, then $F$ is not surjective.
Proof. We can think of the power set as being made up of functions with domain $S$ and image $\{0,1\}$ (by using characteristic functions). If $F\colon S\to P(S)$ is any function, then let $f_s\colon S\to \{0,1\}$ be the function corresponding to the subset $F(s)$. Then $\{f_s\}_{s\in S}$ is a family of functions indexed by $S$ with domain $S$ and codomain having at least two elements. By the Diagonal Argument, the function $g\colon S\to \{0,1\}$ given by
$$g(s) = \left\{\begin{array}{ll}
1 & \text{if }f_s(s)=0,\\
0 &\text{if }f_s(s)=1
\end{array}\right.$$
is not in the family, hence not in the image of $F$. $\Box$
Note that thinking about sets and subsets, the definition of $g$ gives the subset
$$g = \{ s\in S\mid s\notin F(s)\}$$
which is the way we usually see the proof of Cantor's Theorem.
2. Cantor's second proof of uncountability of the reals numbers. If $F\colon\mathbb{N}\to[0,1]$ is a function, then $F$ is not surjective. In particular, there is no surjection from $\mathbb{N}$ to $[0,1]$.
Proof. Consider the real numbers in $[0,1]$. Let $\mathbb{N}$ denote the positive integers. We think of each such real number $r$ as a function $r\colon\mathbb{N}\to\{0,1,2,3,4,5,6,7,8,9\}$, where $r(k)$ is the $k$th digit in the decimal expression for $r$ (having chosen the expression that does not have a tail of $9$s, if such exists); conversely, every function from $\mathbb{N}$ to $\{0,1,2,3,\ldots,9\}$ determines a real number (thought two different functions make determine the same real number, if one of them has a tail of $9$s... we'll ignore this because we can avoid the issue in the argument). Now let $F\colon\mathbb{N}\to[0,1]$ be a function. We let $f_n$ be the function determined by the real number $F(n)$. We now look at the family $\Bigl\{f_n\colon\mathbb{N}\to\{0,1,\ldots,9\}\Bigr\}_{n\in\mathbb{N}}$, and choose $a$ and $b$ as in the Diagonal Argument to be $5$ and $6$. The Diagonal Argument produces a function $g\colon\mathbb{N}\to\{0,1,2,\ldots,9\}$ that is not in our original family, hence a real number $g$ that is not in the image of $F$, as desired. (Because $g$ only takes values in $\{5,6\}$, the issue of dual decimal representation is irrelevant). $\Box$
Viewing the function $g$ as a real number, we see that it is a real number whose $n$th decimal digit is different from the $n$th decimal digit of the $n$th number in our original list $F$; that is, the usual way the argument is presented.
3. Theorem. The set of function $\mathbb{R}\to\mathbb{R}$ cannot be put in bijective correspondence with $\mathbb{R}$. Equivalently: if $F\colon\mathbb{R}\to \mathbb{R}^{\mathbb{R}}$ is a function, then $F$ is not surjective.
(Here $\mathbb{R}^{\mathbb{R}}$ is the set of function from $\mathbb{R}$ to $\mathbb{R}$)
Proof. Let $F\colon\mathbb{R}\to\mathbb{R}^{\mathbb{R}}$. Let $f_r=F(r)$ for each $r\in \mathbb{R}$. Then $\{f_r\}_{r\in \mathbb{R}}$ is a family of functions from $\mathbb{R}$ to $\mathbb{R}$ indexed by $\mathbb{R}$. By the Diagonal Argument, there is a function $G\colon\mathbb{R}\to\mathbb{R}$ that is not one of the $f_r$; i.e., not in the image of $F$. $\Box$
Here we can construct the function $G$ by picking any two reals as in the Diagonal Argument, or as in the parenthetical comment I made below it, by just defining $G(r)$ to be a number different from $f_r(r)$, for instance $f_r(r)+1$, as the author does.