Need to install minimum 10.9.4 for XCode, but running 2009 iMac with 2GB Ram, only option now is Yosemite
A friend of mine recently upgraded his MacBook5,1 (2009 core 2 duo) with 2GB to Mavericks. It wasn't the most pleasant thing, but it actually didn't work out too bad for him and he even thinks there was a slight performance increase (I'm assuming due to the memory compression stuff being a touch faster than swap). I'm assuming that Yosemite isn't going to be much more stressful than Mavericks, so you can probably get away with it.

That being said, 2GB is absolutely too little for a machine that you're going to run Xcode on. Regardless of Mountain Lion, Mavericks or Yosemite, you need more RAM. Period.