Archive

Tag Archives: active_support

This is just an odd little note, since it took me a couple of searches to determine what the deal was. I had an XML string that I got from a SOAP call, and I wanted to do a quick conversion to JSON. Since I know the string’s going to be fairly small, the overhead’s not going to be too bad. So I tried to do a simple:

puts Hash.from_xml(response).to_json

Oddly, I got undefined method `from_xml' for Hash:Class (NoMethodError). That’s weird, I thought; I know that method exists. After checking ruby-docs, though, in fact it doesn’t — if you’re not in Rails. I was running this as a standalone test program. Sure enough, I brought up a Rails console and tested it, and there’s the method.

It just took a quick check then to confirm that, indeed, the from_xml() method is added by ActiveSupport. Putting this in:

require 'active_support'

Took care of the problem. Although I also had to add a to_s to the response in order to make it look like a String.

UPDATE: Thanks to Andrew for his comment below. Now for ActiveSupport 3 you may need to use this instead:

require ‘active_support/core_ext’

Silly little problem, but in case this will help someone out, here it is.

Follow

Get every new post delivered to your Inbox.