我想从 ActiveSupport::SafeBuffer 中获取字符串对象。方法 to_s 返回相同类型的 ActiveSupport::SafeBuffer。只有 to_sym.to_s 返回 String,但这更像是一种 hack。这是我的控制台播放:
irb(main):008:0> s = ActiveSupport::SafeBuffer.new("asdf")
# => "asdf"
irb(main):009:0> s.class
# => ActiveSupport::SafeBuffer
irb(main):010:0> s.to_s.class
# => ActiveSupport::SafeBuffer
irb(main):011:0> s.to_sym.to_s
# => "asdf"
irb(main):012:0> s.to_sym.to_s.class
# => String