How to transform a Hash object into XML using the Rexle-builder gem

require 'rexle-builder'
require 'rexle'

h = {fun: '123', colour: 'red'}

def build(xml, h)
  h.each_pair {|key, value| xml.send(key.to_sym, value) }
end

xml = RexleBuilder.new

puts Rexle.new(xml.root { build xml, h }).xml pretty: true

Output:

<?xml version='1.0' encoding='UTF-8'?>
<root>
  <fun>123</fun>
  <colour>red</colour>
</root>