Regression of Hash#reject in Ruby 2.1.1

In Ruby 2.1.0 or earlier, the reject method in any class that inheritsHash returns an object of its own class.But in Ruby 2.1.1, this behavior has changed accidentally to return alwaysa plain Hash object, not of the inherited class.

class SubHash < Hashendp Hash.new.reject { }.class#=> 2.1.0: Hash, 2.1.1: Hashp SubHash.new.reject { }.class#=> 2.1.0: SubHash, 2.1.1: Hash

(To be exact, extra states such as instance variables, etc. aren’tcopied either.)

Ruby 2.1.1 shouldn’t include such behavior changes, because with the releaseof Ruby 2.1.0 we’ve changed our versioning policy,so Ruby 2.1.1 is a patch level release and it shouldn’t break backwardscompatibility.

This regression could potentially affect many libraries, one such case isRails’ HashWithIndifferentAccess and OrderedHash. They are broken:Rails’ issue #14188.

This behavior will be reverted to the 2.1.0 behavior in Ruby 2.1.2,but is expected to be the default behavior for Ruby 2.2.0:Feature #9223.So we recommend to fix your code in order to expect this behavior change.

This accident is caused by one missing backport commit. For more details, seehttp://blog.sorah.jp/2014/03/10/hash-reject-regression-in-ruby211.

Sorry for any inconvenience, and thank you for your support.

Posted by sorah on 10 Mar 2014

Regression of Hash#reject in Ruby 2.1.1

相关文章:

你感兴趣的文章:

标签云: