2

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.

Machavity
  • 30,841
  • 27
  • 92
  • 100
franksort
  • 3,093
  • 2
  • 19
  • 27

1 Answers1

2

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.

Max
  • 21,123
  • 5
  • 49
  • 71
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317