我在Sinatra应用程序中使用Hash#to_xml。在我移至actviesupport 3.0.0之前,它一直有效

3.0.0中activesupport的用法是否有所不同?

例如,这很好

gem 'activesupport', '2.3.5'
require 'active_support'
{}.to_xml


gem 'activesupport', '3.0.0'
require 'active_support'
{}.to_xml

生成:NoMethodError:{}的未定义方法“to_xml”:哈希

最佳答案

当您对它进行require编码时,ActiveSupport不再加载其所有组件。这使您可以挑选所需的功能。

require "active_support/core_ext/hash/conversions"
{}.to_xml

或者,如果您真的想要所有ActiveSupport:
require "active_support/all"

关于ruby - 如何解决与2.x相比activesupport 3.0.0的行为差异?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3642905/

10-09 00:07