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.
Ruby Doc有两个部分:Core和Standard。核心是默认的,标准有额外的库/方法等。这是否意味着我必须要求这些标准库才能使用它们?我这么认为,从标准库中选择了DateTime.now而不需要任何东西,而且它有效。
1 个解决方案
#1
10
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似乎不在核心(你可能在rails控制台内运行你的线路吗?)
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
但是,只有少数时间方法在核心。要获得更多功能(如Time.parse),您必须这样做
require 'time'
#1
10
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似乎不在核心(你可能在rails控制台内运行你的线路吗?)
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
但是,只有少数时间方法在核心。要获得更多功能(如Time.parse),您必须这样做
require 'time'