diff options
author | thedarkone <thedarkone2@gmail.com> | 2010-09-27 14:48:06 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2010-09-27 17:45:58 +0200 |
commit | 5a518487fe66b11b81e21dc6c31d036057a410ed (patch) | |
tree | 8b3cbece8b7af5b56d214c5e0bc19a8a6eeb4d02 /activesupport/lib/active_support/ordered_options.rb | |
parent | 8cda132136a766621b4c976cb1df7007d12ee6b5 (diff) | |
download | rails-5a518487fe66b11b81e21dc6c31d036057a410ed.tar.gz rails-5a518487fe66b11b81e21dc6c31d036057a410ed.tar.bz2 rails-5a518487fe66b11b81e21dc6c31d036057a410ed.zip |
Try to use Hash's native #[] for speed.
Diffstat (limited to 'activesupport/lib/active_support/ordered_options.rb')
-rw-r--r-- | activesupport/lib/active_support/ordered_options.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 99c6c5a0c0..124e1a74f8 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -18,6 +18,9 @@ require 'active_support/ordered_hash' # module ActiveSupport #:nodoc: class OrderedOptions < OrderedHash + alias_method :_get, :[] # preserve the original #[] method + protected :_get # make it protected + def []=(key, value) super(key.to_sym, value) end @@ -37,7 +40,10 @@ module ActiveSupport #:nodoc: class InheritableOptions < OrderedOptions def initialize(parent = nil) - if parent + if parent.kind_of?(OrderedOptions) + # use the faster _get when dealing with OrderedOptions + super() { |h,k| parent._get(k) } + elsif parent super() { |h,k| parent[k] } else super() |