Question

How do I require and use a library from the Ruby Standard Library such as DateTime?

I'm using rvm. I created a new project and specified which version of Ruby I'd like (in this case 2.1.0) and gave the project its own Gemset.

mkdir proj
cd proj
rvm use ruby-2.1.0
rvm gemset create proj
echo 'ruby-2.1.0' > .ruby-version
echo 'proj' > .ruby-gemset
touch proj.rb

I'd like proj.rb to require DateTime, make a new instance of a DateTime object, then exit.

Was it helpful?

Solution

Do as below

require 'date'
DateTime.parse '12Feb,2014'

You just need to write require 'date', now you will be able to use all methods from the DateTime class API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top