With the game tied 1-1 in the third, the Phillies erupted for four runs to grab control of the contest.
That brought up Ruiz, who crushed a 2-0 pitch into the left-field bleachers for the decisive blow.
Domonic Brown also homered and Darin Ruf added his first major-league shot for Philadelphia, which took the opener of a three-game series.
Cole Hamels (16-6) earned the win, yielding three runs on seven hits over five complete innings. He struck out six.
Jonathan Papelbon picked up his 37th save in the ninth.
Kurt Suzuki went 3-for-4 with an RBI for the National League East-leading Nationals.
McPhee, Cokas 'working on their marriage' after affair
LGBT community has 'bullied the American people': Bachmann