require "nokogiri"
doc = Nokogiri::HTML::Document.new("<title> Save the page! </title>")
doc.class # => Nokogiri::HTML::Document
doc = Nokogiri::HTML::Document.parse <<-eof
<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Ståle Refsnes">
<meta charset="UTF-8">
</head>
eof
doc.class # => Nokogiri::HTML::Document
doc.meta_encoding # => nil
puts doc.to_html
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
# >> <html><head>
# >> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
# >> <meta name="description" content="Free Web tutorials">
# >> <meta name="keywords" content="HTML,CSS,XML,JavaScript">
# >> <meta name="author" content="Ståle Refsnes">
# >> <meta charset="UTF-8">
# >> </head></html>
Why Nokogiri::HTML::Document#meta_encoding returns nil ?