Including core class extensions from gems

Discussion in 'Ruby' started by Shanti Braford, Jan 5, 2007.

  1. 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/

    --
    Posted via http://www.ruby-forum.com/.
    Shanti Braford, Jan 5, 2007
    #1
    1. Advertising

  2. Shanti Braford

    Eric Hodel Guest

    On Jan 5, 2007, at 03:22, Shanti Braford wrote:

    > 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'


    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.

    --
    Eric Hodel - - http://blog.segment7.net

    I LIT YOUR GEM ON FIRE!
    Eric Hodel, Jan 5, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tomás

    Gems -- #include <gems.hpp>

    Tomás, Mar 4, 2006, in forum: C++
    Replies:
    7
    Views:
    412
    Tomás
    Mar 5, 2006
  2. Lloyd Zusman
    Replies:
    3
    Views:
    173
    Lloyd Zusman
    Jun 21, 2005
  3. Dany Cayouette

    'private' gems/gems hierarchy

    Dany Cayouette, Nov 25, 2005, in forum: Ruby
    Replies:
    3
    Views:
    149
    Jim Weirich
    Nov 25, 2005
  4. Thaddeus L Olczyk

    Problem getting gems/listing gems. EINVAL

    Thaddeus L Olczyk, Aug 15, 2006, in forum: Ruby
    Replies:
    0
    Views:
    180
    Thaddeus L Olczyk
    Aug 15, 2006
  5. Carlos Fernandez

    include core class extensions

    Carlos Fernandez, Mar 27, 2007, in forum: Ruby
    Replies:
    2
    Views:
    80
    Carlos Fernandez
    Mar 28, 2007
Loading...

Share This Page