What is the oxidation number of the oxygen in BaO2 According to the book for a binary compound, first we assign the element with greater electronegativity its oxidation number (oxygen always -2 except in peroxides). So, we have 
-2 x2 =-2. So, each oxygen would have an oxidation number of -2. The book says the answer is -1. 

The only thing I can think of, is since barium is an alkaline metal, it has an oxidation number of +2, so each oxygen would be -1. But, it contradicts itself because in the rules. It says for a binary compound, "the element with greater electronegativity is assigned a negative oxidation number equal to its charge in simple ionic compounds of the element."
"oxygen always -2 except in peroxides"


This exception is in effect here, because $\ce{BaO2}$ is a peroxide consisting of $\ce{Ba^{2+}}$ and $\ce{O2^{2-}}$ ions. The oxidation number of Ba is +II, and the oxidation number of each of the oxygens in the peroxide anion is -I. This fits with the charge of the peroxide anion ($2 \times -1 = -2$), and as $\ce{BaO2}$ is a neutral compound, the sum of all oxidation numbers is 0. Moreover, there are even more exceptions to the rule of thumb cited above, for example, the superoxide radical anion $\ce{O2-}$ with a fractional oxidation numer of $-\frac{1}{2}$, or the dioxygenyl cation $\ce{O2+}$ with a formal oxidation number of $+\frac{1}{2}$ for each oxygen.

In contrast to peroxides, "simple ionic compounds" of oxygen are oxides, which contain the anion $\ce{O^{2-}}$. The charge of the oxide anion is $2-$, so the oxidation number of oxygen in those compounds is -II.