Since V1.6.8 is supported by comment -option, you do not need to work with << .
If you need a comment tag, you can use comment_ (with an underscore at the end).
Example:
builder = Nokogiri::XML::Builder.new do |xml| xml.root { xml.comment 'My comment' xml.comment_ 'My comment-tag' } end puts builder.to_xml
Result:
<?xml version="1.0"?> <root> <comment>My comment-tag</comment> </root>
source share