diff options
author | Nikita Afanasenko <nikita@afanasenko.name> | 2012-11-03 15:25:27 +0400 |
---|---|---|
committer | Nikita Afanasenko <nikita@afanasenko.name> | 2012-11-04 14:33:39 +0400 |
commit | 9cda6a321e1fb8fd6d0b9d368bd1868fb142b93a (patch) | |
tree | 6a55fcb683efac3589f2685173f1e993ad2ae77f /activesupport/lib/active_support | |
parent | c449462f45d342258a01313c0ff46279d268719d (diff) | |
download | rails-9cda6a321e1fb8fd6d0b9d368bd1868fb142b93a.tar.gz rails-9cda6a321e1fb8fd6d0b9d368bd1868fb142b93a.tar.bz2 rails-9cda6a321e1fb8fd6d0b9d368bd1868fb142b93a.zip |
Use `tag!` instead of `method_missing` in `to_xml` conversions.
Since version `3.0.x` `Builder` caches method passed to `method_missing` each time. This commit replaces `method_missing` call with `tag!` call to prevent method redefinition on each `to_xml` call with the same builder.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 6a0c4a015a..ff06436bd6 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -194,7 +194,7 @@ class Array options = options.dup options[:indent] ||= 2 - options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent]) options[:root] ||= \ if first.class != Hash && all? { |e| e.is_a?(first.class) } underscored = ActiveSupport::Inflector.underscore(first.class.name) @@ -208,12 +208,12 @@ class Array root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options) children = options.delete(:children) || root.singularize - attributes = options[:skip_types] ? {} : {:type => 'array'} + attributes = options[:skip_types] ? {} : { type: 'array' } if empty? builder.tag!(root, attributes) else - builder.__send__(:method_missing, root, attributes) do + builder.tag!(root, attributes) do each { |value| ActiveSupport::XmlMini.to_tag(children, value, options) } yield builder if block_given? end diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index f5e3a9b842..0e7bb179bf 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -74,14 +74,14 @@ class Hash options = options.dup options[:indent] ||= 2 options[:root] ||= 'hash' - options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent]) builder = options[:builder] builder.instruct! unless options.delete(:skip_instruct) root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options) - builder.__send__(:method_missing, root) do + builder.tag!(root) do each { |key, value| ActiveSupport::XmlMini.to_tag(key, value, options) } yield builder if block_given? end |