RVM is a great tool to manage your ruby versions and set up your working environment.
Assuming you already have RVM installed, to get the latest version of ruby, which is needed for these examples, open a terminal and run:
$ rvm get stable
$ rvm install ruby --latest
Check your ruby version by...