Question

I have a ruby gem and I want to use the Hash.from_xml method in the gem that is included in rails active_support module. I have the below code in my gemspec:

gem.add_dependency 'active_support', '~> 3.0.0'

However, when I build and install the gem locally, run irb, require the gem, I am not seeing the methods from active support included?

Any suggestions on what I am doing wrong or how to debug? Thanks!

Was it helpful?

Solution

You need to require the methods you need from ActiveSupport; they aren't added by default.

As Yevgeniy mentioned in a comment, the way to do this is require 'active_support/all' if you need everything - or if, for example, you want only the Hash extensions then use require 'active_support/core_ext/hash'. Note that this usually doesn't go in the gemspec, but rather in whatever file your gem uses to set itself up.

Perhaps even better would be to require the required ActiveSupport files in the actual files needing them, but that's a matter of taste.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top