Search code examples
ruby-on-railsrubyrubygemsdependencies

ruby gem, requiring a rails module bad practice?


I am working on a ruby gem that parses xml. I want to utilize the rails Hash.from_xml method and am wondering if requiring active_support or any large library in a gem is bad practice. Is this adding too much just so I can use its one method, or is this considered standard/ok when building a ruby gem? I would be adding require 'active_support/all' to my gem.


Solution

  • I prefer to require as little as possible and to only cherry-pick the specific definition that I want to use.

    In your example that would look like this:

    require 'active_support'
    require 'active_support/core_ext/hash/conversions'
    

    Read about how to require only specific definitions from ActiveSupport in the official Rails Guides.