我需要做什么才能让Hash.from_xml()工作?

Ami*_*pta 12 ruby xml hash activesupport

我在我的代码中安装了'ActiveSupport'并且需要'active_support',但是当我尝试使用该Hash.from_xml()方法时,我得到了"No Method Error" .

我错过了什么?

$ gem list
Run Code Online (Sandbox Code Playgroud)

收益:

\*** LOCAL GEMS \***

activesupport (3.2.6)  
bundler (1.1.4)  
i18n (0.6.0)  
json (1.7.3)  
mime-types (1.19)  
multi_json (1.3.6)  
rake (0.9.2.2)  
rest-client (1.6.7)  
rubygems-bundler (1.0.3)  
rvm (1.11.3.5)
Run Code Online (Sandbox Code Playgroud)

和:

$ ruby -v
Run Code Online (Sandbox Code Playgroud)

收益:

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Run Code Online (Sandbox Code Playgroud)

内容file.rb是:

require 'active_support'  
require 'rest-client'  
require 'json'  
token = "xxx"  
user = "xxx"  
survey_id = "xxx"  
responses_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getLegacyResponseData&User=#{user}&Token=#{token}&Version=2.0&SurveyID=#{survey_id}&Format=XML"  
responses = Hash.from_xml(responses_from_api).to_json  
puts responses
Run Code Online (Sandbox Code Playgroud)

和:

$ ruby file.rb
Run Code Online (Sandbox Code Playgroud)

收益:

file.rb:8:in `<main>': undefined method `from_xml' for Hash:Class (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

mu *_*ort 36

只是require 'active_support'不做很多,你必须亲自拉出一些碎片.如果你想要所有的ActiveSupport:

require 'active_support/all'
Run Code Online (Sandbox Code Playgroud)

或者如果你只想要Hash扩展:

require 'active_support/core_ext/hash'
Run Code Online (Sandbox Code Playgroud)