diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-13 22:02:29 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-13 22:02:29 +0200 |
commit | 50df162a2b6dea873542d2c4fd055a0e40dad5cc (patch) | |
tree | 49160f144ea777f4010fee2285dd53bdbf957ead /activesupport/lib/active_support | |
parent | e574ca920d315158a4af5c906b23ea0082c5690f (diff) | |
download | rails-50df162a2b6dea873542d2c4fd055a0e40dad5cc.tar.gz rails-50df162a2b6dea873542d2c4fd055a0e40dad5cc.tar.bz2 rails-50df162a2b6dea873542d2c4fd055a0e40dad5cc.zip |
explains why AS::OrderedHash does not leverage inheritance
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/ordered_hash.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 02980d7473..91de722748 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -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 = [] |