我想从ActiveSupport::SafeBuffer中获取String对象。方法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
最佳答案
将其插入为字符串:
irb(main):001:0> "#{ActiveSupport::SafeBuffer.new("asdf")}".class
=> String
关于ruby - 如何将ActiveSupport::SafeBuffer转换为String?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15654676/