Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Ruby Core API and Standard Library API?

Tags:

ruby

Ruby Doc has two sections: Core and Standard. Core comes by default and standard has additional libraries/methods etc. Does it mean I have to require these standard libraries in order to use them? I thought so and picked DateTime.now from standard library without requiring anything, and it worked.

like image 417
Bala Avatar asked Aug 29 '13 08:08

Bala


1 Answers

Yep, you got it right. Core functionality is everything you don't have to require to use.

DateTime seems to be not in the core (are you running your line inside of rails console, maybe?)

DateTime.now # => 
# ~> -:1:in `<main>': uninitialized constant DateTime (NameError)

But Time is

Time # => Time
Time.now # => 2013-08-29 12:32:54 +0400

Only a few methods of Time are in core, though. To get more functionality (like Time.parse) you have to

require 'time'
like image 191
Sergio Tulentsev Avatar answered Oct 21 '22 23:10

Sergio Tulentsev