如何在Ruby中将字符引用转换为UTF-8字符串?

我有一些来自Feed的内容。 在这些提要中,UTF-8字符通常被编码为字符引用,即“å”是“å”。 为了避免在我的视图中对它们进行双重编码(即“å”),我想将它们转换回正常的UTF_8字符​​。 我怎么能在Ruby中做到这一点?

我想要:

“å”。convert_to_utf8 =>“å”

HTMLEntities gem旨在实现这一目标。

require 'htmlentities' coder = HTMLEntities.new string = "élan" coder.decode(string) # => "élan" # or string.decode_entities # => "élan"