Including core class extensions from gems

S

Shanti Braford

Hey all,

This question could just as easily be a good fit for the RoR list, but I
figured it's really more of a Ruby question, pertaining to a
Rails-specific gem in this case.

What I'm trying to do... is leverage Rails' activesupport gem.
Specifically, the new Hash.from_xml method (and all of its related
dependencies).
gem list | grep activesupport
activesupport (1.3.1, 1.2.5)

Check.

This is where I'm a little befuddled as to how to do this the Ruby
way...

A simple test I've worked up to demonstrate whether or not this is
working (hash_from_xml_test.rb):

require 'rubygems'
require_gem 'activesupport', '>= 1.3.1'
require 'active_support'
require 'active_support/core_ext'

class HashFromXmlTest < Test::Unit::TestCase
def test_hash_from_xml
h = Hash.from_xml('<foo>bar</foo>')
assert h.is_a?(Hash)
end
end


Running this gives a "NoMethodError: undefined method `from_xml' for
Hash:Class".

Any ideas?

Cheers,

- Shanti
http://onwebapps.com/
 
E

Eric Hodel

This question could just as easily be a good fit for the RoR list,
but I
figured it's really more of a Ruby question, pertaining to a
Rails-specific gem in this case.

What I'm trying to do... is leverage Rails' activesupport gem.
Specifically, the new Hash.from_xml method (and all of its related
dependencies).

activesupport (1.3.1, 1.2.5)

Check.

This is where I'm a little befuddled as to how to do this the Ruby
way...

A simple test I've worked up to demonstrate whether or not this is
working (hash_from_xml_test.rb):

require 'rubygems'
require_gem 'activesupport', '>= 1.3.1'

You don't need this line at all. Rubygems is smart and knows which
gem to load.

By the way, 'require_gem' is deprecated, use 'gem'
require 'active_support'
require 'active_support/core_ext'

class HashFromXmlTest < Test::Unit::TestCase
def test_hash_from_xml
h = Hash.from_xml('<foo>bar</foo>')
assert h.is_a?(Hash)
end
end


Running this gives a "NoMethodError: undefined method `from_xml' for
Hash:Class".

You probably have to load some other file. I'm sure grep will find
it. If not, try the Rails list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top