File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
activesupport/lib/active_support/core_ext/hash Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,22 @@ class Hash
26
26
#
27
27
# * If +value+ is a callable object it must expect one or two arguments. Depending
28
28
# on the arity, the callable is invoked with the +options+ hash as first argument
29
- # with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. Its
30
- # return value becomes a new node.
29
+ # with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. The
30
+ # callable can add nodes by using <tt>options[:builder]</tt>.
31
+ #
32
+ # "foo".to_xml(lambda { |options, key| options[:builder].b(key) })
33
+ # # => "<b>foo</b>"
31
34
#
32
35
# * If +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.
36
+ #
37
+ # class Foo
38
+ # def to_xml(options)
39
+ # options[:builder].bar "fooing!"
40
+ # end
41
+ # end
42
+ #
43
+ # {:foo => Foo.new}.to_xml(:skip_instruct => true)
44
+ # # => "<hash><bar>fooing!</bar></hash>"
33
45
#
34
46
# * Otherwise, a node with +key+ as tag is created with a string representation of
35
47
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
You can’t perform that action at this time.
0 commit comments