I have to do development on several different machines (keeping them in sync is a real pain, so if you have any good advice please share) and when I went to do some rails work I kept getting this error everytime I'd try to do something:
undefined method `gem' for main:Object
It took me a little while to figure out, but I finally upgraded ruby gems
gem update --system
and things started working again.