1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

explains why AS::OrderedHash does not leverage inheritance

This commit is contained in:
Xavier Noria 2010-06-13 22:02:29 +02:00
parent e574ca920d
commit 50df162a2b

View file

@ -23,6 +23,17 @@ module ActiveSupport
# Hash is ordered in Ruby 1.9!
if RUBY_VERSION < '1.9'
# In MRI the Hash class is core and written in C. In particular, methods are
# programmed with explicit C function calls and polymorphism is not honored.
#
# For example, []= is crucial in this implementation to maintain the @keys
# array but hash.c invokes rb_hash_aset() originally. This prevents method
# reuse through inheritance and forces us to reimplement stuff.
#
# For instance, we cannot use the inherited #merge! because albeit the algorithm
# itself would work, our []= is not being called at all by the C code.
def initialize(*args, &block)
super
@keys = []