ruby 1.9.2和ruby 2.0之间的主要/次要差异是什么?

时间:2022-06-12 20:41:03

I've been told that ruby 1.9.2 is ruby 2.0 but ruby 1.9.3 is slated to be released in the near future and it will contain some performance enhancements.

我被告知ruby 1.9.2是ruby 2.0但ruby 1.9.3将在不久的将来发布,它将包含一些性能增强功能。

So what are they planning for 2.0? Will it be much different than ruby 1.9.x?

那么他们有什么计划2.0?它会与ruby 1.9.x有很大的不同吗?

1 个解决方案

#1


32  

Two features that are already implemented in YARV, and which will most likely end up in Ruby 2.0, are traits (mix) and Module#prepend.

YARV中已经实现的两个功能很可能最终出现在Ruby 2.0中,它们是traits(mix)和Module#prepend。

The mix method, unlike the current include method, takes a list of modules, and mixes all of them in at the same time, making sure that they have no conflicting methods. It also gives you a way to easily resolve conflicts, if e.g. two modules you want to mix in define the same method. So, basically, while the include method allows you to treat a module as a mixin, the mix method allows you to treat a module as a trait.

mix方法与当前的include方法不同,它采用模块列表,并同时混合所有模块,确保它们没有冲突的方法。它还为您提供了一种轻松解决冲突的方法,例如要混合的两个模块定义相同的方法。因此,基本上,虽然include方法允许您将模块视为mixin,但mix方法允许您将模块视为特征。

Module#prepend mixes a module into a class or module, again just like include does, but instead of inserting it into the inheritance chain just above the class, it inserts is just below the class. This means that methods in the module can override methods in the class, and they can delegate to the overriden methods with super, both of which is not possible when using include. This basically makes alias_method_chain obsolete.

Module #prepend将一个模块混合到一个类或模块中,就像include do一样,但不是将它插入到类上面的继承链中,而是插入在类的下面。这意味着模块中的方法可以覆盖类中的方法,并且它们可以使用super委托给overriden方法,这两种方法在使用include时都是不可能的。这基本上使alias_method_chain过时了。

One feature that has been discussed for a couple of months (or 10 years, depending on how you count), are Refinements. There has been discussion for over 10 years now to add a way to do scoped, safe monkey patching in Ruby. I.e. a way where I can monkey patch a core class, but only my code sees that monkey patch, other code doesn't. For many years, the frontrunner for that kind of safe monkey patching were Selector Namespaces, however more recently, Classboxes have been getting a lot of attention, and even more recently, a prototype implementation and specification of Refinements, a variant of Classboxes, was put forward.

一个已经讨论了几个月(或10年,取决于你如何计算)的特征是精炼。现在已经讨论了10多年来添加一种在Ruby中进行范围化,安全的猴子修补的方法。即我可以修补核心类的方法,但只有我的代码看到猴子补丁,其他代码没有。多年来,这种安全猴子补丁的领跑者是Selector Namespaces,但是最近,Classboxes受到了很多关注,甚至最近,一个原型实现和Refinements规范,Classboxes的变种,被放置了前锋。

Generally speaking, the big theme of Ruby 2.0 is scalability: scaling up to bigger teams, bigger codebases, bigger problem sizes, bigger machines, more cores. But also scaling down to smaller machines like embedded devices.

一般来说,Ruby 2.0的主题是可扩展性:扩展到更大的团队,更大的代码库,更大的问题规模,更大的机器,更多的核心。但也可以缩小到嵌入式设备等小型机器。

The three features I mentioned above are for scaling to bigger teams and bigger codebases. Some proposed features for scaling to bigger problem sizes and more cores are parallel collections and parallel implementations of Enumerable methods such as map, as well as better concurrency abstractions such as futures, promises, agents, actors, channels, join patterns or something like that.

我上面提到的三个功能是扩展到更大的团队和更大的代码库。一些用于扩展到更大问题大小和更多核心的建议功能是并行集合和可枚举方法(如map)的并行实现,以及更好的并发抽象,如期货,承诺,代理,参与者,渠道,联接模式或类似的东西。

#1


32  

Two features that are already implemented in YARV, and which will most likely end up in Ruby 2.0, are traits (mix) and Module#prepend.

YARV中已经实现的两个功能很可能最终出现在Ruby 2.0中,它们是traits(mix)和Module#prepend。

The mix method, unlike the current include method, takes a list of modules, and mixes all of them in at the same time, making sure that they have no conflicting methods. It also gives you a way to easily resolve conflicts, if e.g. two modules you want to mix in define the same method. So, basically, while the include method allows you to treat a module as a mixin, the mix method allows you to treat a module as a trait.

mix方法与当前的include方法不同,它采用模块列表,并同时混合所有模块,确保它们没有冲突的方法。它还为您提供了一种轻松解决冲突的方法,例如要混合的两个模块定义相同的方法。因此,基本上,虽然include方法允许您将模块视为mixin,但mix方法允许您将模块视为特征。

Module#prepend mixes a module into a class or module, again just like include does, but instead of inserting it into the inheritance chain just above the class, it inserts is just below the class. This means that methods in the module can override methods in the class, and they can delegate to the overriden methods with super, both of which is not possible when using include. This basically makes alias_method_chain obsolete.

Module #prepend将一个模块混合到一个类或模块中,就像include do一样,但不是将它插入到类上面的继承链中,而是插入在类的下面。这意味着模块中的方法可以覆盖类中的方法,并且它们可以使用super委托给overriden方法,这两种方法在使用include时都是不可能的。这基本上使alias_method_chain过时了。

One feature that has been discussed for a couple of months (or 10 years, depending on how you count), are Refinements. There has been discussion for over 10 years now to add a way to do scoped, safe monkey patching in Ruby. I.e. a way where I can monkey patch a core class, but only my code sees that monkey patch, other code doesn't. For many years, the frontrunner for that kind of safe monkey patching were Selector Namespaces, however more recently, Classboxes have been getting a lot of attention, and even more recently, a prototype implementation and specification of Refinements, a variant of Classboxes, was put forward.

一个已经讨论了几个月(或10年,取决于你如何计算)的特征是精炼。现在已经讨论了10多年来添加一种在Ruby中进行范围化,安全的猴子修补的方法。即我可以修补核心类的方法,但只有我的代码看到猴子补丁,其他代码没有。多年来,这种安全猴子补丁的领跑者是Selector Namespaces,但是最近,Classboxes受到了很多关注,甚至最近,一个原型实现和Refinements规范,Classboxes的变种,被放置了前锋。

Generally speaking, the big theme of Ruby 2.0 is scalability: scaling up to bigger teams, bigger codebases, bigger problem sizes, bigger machines, more cores. But also scaling down to smaller machines like embedded devices.

一般来说,Ruby 2.0的主题是可扩展性:扩展到更大的团队,更大的代码库,更大的问题规模,更大的机器,更多的核心。但也可以缩小到嵌入式设备等小型机器。

The three features I mentioned above are for scaling to bigger teams and bigger codebases. Some proposed features for scaling to bigger problem sizes and more cores are parallel collections and parallel implementations of Enumerable methods such as map, as well as better concurrency abstractions such as futures, promises, agents, actors, channels, join patterns or something like that.

我上面提到的三个功能是扩展到更大的团队和更大的代码库。一些用于扩展到更大问题大小和更多核心的建议功能是并行集合和可枚举方法(如map)的并行实现,以及更好的并发抽象,如期货,承诺,代理,参与者,渠道,联接模式或类似的东西。