4

I have created modules to add some extra functions to the existing libraries, which include both ruby built-in library and third party library (like String, Hash, ActiveModel and Nokogiri).

such as

# extension for ExistingClass
module SomeExtension
  def extra_method
    ... 
  end
end

ExistingClass.send(:include, SomeExtension::extra_method)

Where is the best location to put them in?

5t111111
  • 700
  • 5
  • 14

1 Answers1

4

Probably lib.

lib/core_ext can contain extensions for standard functions, and vendor-named directories under lib for others.

config/initializers is another commonly used location.

I'd recommend spending time looking at other projects to find what seems most common and works best for you.

Some links that may be of interest:

Community
  • 1
  • 1
TK-421
  • 10,598
  • 3
  • 38
  • 34