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

后端 未结 1 1392
太阳男子
太阳男子 2021-01-01 21:36

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 stan

相关标签:
1条回答
  • 2021-01-01 22:19

    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'
    
    0 讨论(0)
提交回复
热议问题