Ruby 核心 API 和标准库 API 有什么区别? [英] What's the difference between Ruby Core API and Standard Library API?

查看:50
本文介绍了Ruby 核心 API 和标准库 API 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby Doc 有两个部分:核心部分和标准部分.Core 是默认的,standard 有额外的库/方法等.这是否意味着我必须 require 这些标准库才能使用它们?我是这么想的,然后从标准库中选择了 DateTime.now 而不需要任何东西,它工作了.

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.

推荐答案

是的,你没看错.核心功能是您不必要求使用的一切.

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

DateTime 似乎不在核心中(您是否在 rails 控制台内运行您的线路,也许?)

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)

但是时间

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

不过,只有少数 Time 方法是核心.要获得更多功能(例如 Time.parse),您必须

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

require 'time'

这篇关于Ruby 核心 API 和标准库 API 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆