aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNick Sutterer <apotonick@gmail.com>2011-01-06 14:33:20 +0100
committerPiotr Sarnacki <drogus@gmail.com>2011-01-06 17:57:09 +0100
commit7773c3240048d66d09afa1658c6f49b5de54bbe8 (patch)
treecd4dfaca90661e6344ab4b8cc1242e0241968b36 /activesupport
parent54f3aa86334917bdc947b242c277060a2cfe7b72 (diff)
downloadrails-7773c3240048d66d09afa1658c6f49b5de54bbe8.tar.gz
rails-7773c3240048d66d09afa1658c6f49b5de54bbe8.tar.bz2
rails-7773c3240048d66d09afa1658c6f49b5de54bbe8.zip
corrected docs for Hash#to_xml and added examples.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 4e8ec5a3a8..3005fef44c 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -26,10 +26,22 @@ class Hash
#
# * If +value+ is a callable object it must expect one or two arguments. Depending
# on the arity, the callable is invoked with the +options+ hash as first argument
- # with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. Its
- # return value becomes a new node.
+ # with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. The
+ # callable can add nodes by using <tt>options[:builder]</tt>.
+ #
+ # "foo".to_xml(lambda { |options, key| options[:builder].b(key) })
+ # # => "<b>foo</b>"
#
# * If +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.
+ #
+ # class Foo
+ # def to_xml(options)
+ # options[:builder].bar "fooing!"
+ # end
+ # end
+ #
+ # {:foo => Foo.new}.to_xml(:skip_instruct => true)
+ # # => "<hash><bar>fooing!</bar></hash>"
#
# * Otherwise, a node with +key+ as tag is created with a string representation of
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.