What is the difference between the Ruby Core API and the standard library API?

Ruby Doc has two sections: Core and Standard. Core comes by default, and the standard has additional libraries / methods, etc. Does this mean that I need to use these standard libraries to use them? I thought so and chose DateTime.now from the standard library without requiring anything, and it worked.

+6
source share
1 answer

Yes, you got it right. Basic functionality is all you do not need to use require .

DateTime doesn't seem to be in the kernel (you can run your line inside the rails console, maybe?)

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

But there is time

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

At the core are just a few Time methods. To get more functionality (e.g. Time.parse ), you should

 require 'time' 
+10
source

Source: https://habr.com/ru/post/952721/


All Articles