ruby版本管理_如何管理您的Ruby版本

ruby版本管理

Ruby随时间而改变 (Ruby has changed over time)

Ruby has been in constant development since the 1990s. And like many languages, there have been syntax changes across versions. This means that it is important to be clear about which Ruby version your code expects.

自1990年代以来,Ruby一直在不断发展。 与许多语言一样,各个版本的语法也有所变化。 这意味着弄清楚您的代码期望使用哪个Ruby版本是很重要的。

Probably the most visible change came with Ruby 1.9. Previously, we wrote hashes like this:

可能最明显的变化是Ruby 1.9。 以前,我们这样写哈希:

{ :one => 1, :two => 2, :three => 3 }

This use of the ‘hashrocket’ operator (=>) was so common, that Ruby 1.9 provided a shorthand:

这种对'hashrocket'运算符( => )的用法是如此普遍,以至于Ruby 1.9提供了一个简写形式:

{ one: 1, two: 2, three: 3 }

This older code will run on any version, but the newer syntax will only run on Ruby 1.9+.

此旧代码可在任何版本上运行,但新语法仅可在Ruby 1.9+上运行。

这是怎么引起问题的? (How does this cause problems?)

For example, you might have decided to use a Gem which internally relies on Ruby 1.9 features. This means that your project now also relies on Ruby 1.9 features.

例如,您可能已决定使用内部依赖Ruby 1.9功能的Gem。 这意味着您的项目现在还依赖于Ruby 1.9功能。

If you don’t specify which version of Ruby your project needs, it can be very confusing when code works on one machine, but not another.

如果您没有指定项目需要的Ruby版本,那么当代码在一台计算机上运行而不在另一台计算机上运行时,这可能会非常混乱。

As with most languages, it’s considered good practice to specify the version of Ruby that your code expects. This makes it much easier to manage multiple projects on your development machine, each expecting a different version of Ruby.

与大多数语言一样,指定代码期望的Ruby版本被认为是一种好习惯。 这使得在开发机器上管理多个项目(每个项目都期望使用不同版本的Ruby)变得更加容易。

如何指定我的Ruby版本? (How do I specify my Ruby version?)

There are a couple of tools which are popular for this, but both have agreed to share a common file. Many Ruby (or Rails) projects will include a simple .ruby-version file, which simply specifies a version number, for example:

有两种流行的工具,但都同意共享一个公共文件。 许多Ruby(或Rails)项目将包含一个简单的.ruby-version文件,该文件仅指定版本号,例如:

2.4.2

Popular tools to help you manage your Ruby version are:

可以帮助您管理Ruby版本的流行工具是:

Let’s look at RVM.

让我们看一下RVM。

使用RVM (Using RVM)

RVM is typically installed (link) on a Linux, Unix or MacOS machine. It is very convenient because it hooks into the cd (change directory) command. So when you move to a new project, your .ruby-version is read automatically, and you’re automatically switched to the correct version of Ruby before you start working.

RVM通常安装( 链接 )在Linux,Unix或MacOS计算机上。 这是非常方便的,因为它挂钩到cd ( c焊割d irectory)命令。 因此,当您移至新项目时,将自动读取.ruby-version ,并在开始工作之前自动切换到正确的Ruby版本。

For example, you might have this sequence:

例如,您可能具有以下顺序:

% cd ~/projects/older-project
% ruby --version

ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin16]

% cd ~/projects/newer-project
% ruby --version

ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]

(These examples are from a MacOS machine).

(这些示例来自MacOS计算机)。

有关Ruby的其他信息: (Other info on Ruby:)

翻译自: https://www.freecodecamp.org/news/how-to-manage-your-ruby-versions/

ruby版本管理

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值