The first ruby can be bought at character Level 10 from your class trainer. You can buy one ruby for every character level after that.
You will receive up to six rubies from completing certain World Mysteries quests, one for achieving the highest possible amount of Combat Glory, and one for completing a level 40 quest that involves gathering Astral Gemstones. You can also get five rubies for completing the Great Mage's Diary quest line, one ruby for each page (though achieving this is nearly impossible).
Rubies can be spent in the Talent Grids tabs of the Talent panel. To unlock a talent, you need to connect it with the middle square of the grid. You can only connect them by selecting squares horizontally or vertically, spending 1 ruby at each square, which means that you might have to waste some rubies to get certain talents. Each talent square can be chosen once, but there are duplicate squares that can be stacked with each other.
You can see an example of a Talent Grid on the right. To get the highlighted talent, a mage will have to spend 3 Rubies to connect it to the middle square, and one Ruby to unlock the talent.