9

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!

4

1 回答 1

14

你需要你需要require的方法ActiveSupport;默认情况下不添加它们。

正如 Yevgeniy 在评论中提到的那样,这样做的方法是require 'active_support/all'如果您需要所有东西 - 或者,例如,如果您只想要Hash扩展然后使用require 'active_support/core_ext/hash'. 请注意,这通常不在 gemspec 中,而是在您的 gem 用来设置自己的任何文件中。

也许更好的是在需要它们的实际文件中require的所需ActiveSupport文件,但这是一个品味问题。

于 2013-09-11T07:19:47.917 回答