File: //usr/local/rvm/gems/default/doc/activesupport-6.1.4.1/ri/Hash/to_xml-i.ri
U:RDoc::AnyMethod[iI"to_xml:ETI"Hash#to_xml;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"GReturns a string containing an XML representation of its receiver:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"{ foo: 1, bar: 2 }.to_xml
;TI"
# =>
;TI".# <?xml version="1.0" encoding="UTF-8"?>
;TI"# <hash>
;TI"%# <foo type="integer">1</foo>
;TI"%# <bar type="integer">2</bar>
;TI"# </hash>
;T:@format0o;
; [I"OTo do so, the method loops over the pairs and builds nodes that depend on ;TI"/the _values_. Given a pair +key+, +value+:;T@o:RDoc::Markup::List:
@type:BULLET:@items[
o:RDoc::Markup::ListItem:@label0; [o;
; [I"PIf +value+ is a hash there's a recursive call with +key+ as <tt>:root</tt>.;T@o;;0; [o;
; [I"SIf +value+ is an array there's a recursive call with +key+ as <tt>:root</tt>, ;TI"2and +key+ singularized as <tt>:children</tt>.;T@o;;0; [o;
; [ I"TIf +value+ is a callable object it must expect one or two arguments. Depending ;TI"Uon the arity, the callable is invoked with the +options+ hash as first argument ;TI"Rwith +key+ as <tt>:root</tt>, and +key+ singularized as second argument. The ;TI"@callable can add nodes by using <tt>options[:builder]</tt>.;T@o;; [I"F{foo: lambda { |options, key| options[:builder].b(key) }}.to_xml
;TI"# => "<b>foo</b>"
;T;
0o;;0; [o;
; [I"XIf +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.;T@o;; [I"class Foo
;TI" def to_xml(options)
;TI") options[:builder].bar 'fooing!'
;TI" end
;TI" end
;TI"
;TI"2{ foo: Foo.new }.to_xml(skip_instruct: true)
;TI"
# =>
;TI"# <hash>
;TI"# <bar>fooing!</bar>
;TI"# </hash>
;T;
0o;;0; [o;
; [ I"TOtherwise, a node with +key+ as tag is created with a string representation of ;TI"Z+value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added. ;TI"WUnless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is ;TI"6added as well according to the following mapping:;T@o;; [I"XML_TYPE_NAMES = {
;TI"! "Symbol" => "symbol",
;TI"" "Integer" => "integer",
;TI"" "BigDecimal" => "decimal",
;TI" "Float" => "float",
;TI"" "TrueClass" => "boolean",
;TI"" "FalseClass" => "boolean",
;TI" "Date" => "date",
;TI"# "DateTime" => "dateTime",
;TI"" "Time" => "dateTime"
;TI"}
;T;
0o;
; [I"_By default the root node is "hash", but that's configurable via the <tt>:root</tt> option.;T@o;
; [I"YThe default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can ;TI"[configure your own builder with the <tt>:builder</tt> option. The method also accepts ;TI"Uoptions like <tt>:dasherize</tt> and friends, they are forwarded to the builder.;T:
@fileI"4lib/active_support/core_ext/hash/conversions.rb;T:0@omit_headings_from_table_of_contents_below00I"builder;T[ I"(options = {});T@dFI" Hash;TcRDoc::NormalClass00