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!
Requiring code RubyGems modifies your Ruby load path, which controls how your Ruby code is found by the require statement. When you require a gem, really you're just placing that gem's lib directory onto your $LOAD_PATH .
A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.
What does gem install do? gem install , in its simplest form, does something kind of like this. It grabs the gem and puts its files into a special directory on your system. You can see where gem install will install your gems if you run gem environment (look for the INSTALLATION DIRECTORY: line):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With