corrected docs for Hash#to_xml and added examples.
This commit is contained in:
parent
54f3aa8633
commit
7773c32400
@ -26,11 +26,23 @@ class Hash
|
|||||||
#
|
#
|
||||||
# * If +value+ is a callable object it must expect one or two arguments. Depending
|
# * 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
|
# 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
|
# with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. The
|
||||||
# return value becomes a new node.
|
# 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>.
|
# * 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
|
# * 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.
|
# +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
|
||||||
# Unless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is
|
# Unless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is
|
||||||
|
Loading…
Reference in New Issue
Block a user