如何修复activesupport 3.0.0与2.x相比的行为差异?

时间:2010-09-04 15:40:27

标签: ruby activesupport

我在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':哈希

1 个答案:

答案 0 :(得分:9)

ActiveSupport在您require时不再加载其所有组件。这使您可以选择所需的功能。

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

或者如果你真的想要所有的ActiveSupport:

require "active_support/all"