Posted By

blasterpal on 09/18/09


include MODULES directory a all in dynamically

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Dynamically include all modules in a directory

 / Published in: Ruby


This assumes the modules names are CamelCase and not UPPERCASE.

  1. #assumes all modules follow UpperUpper format with file name lower_lower.rb.
  2. Dir[File.join(File.dirname(__FILE__), '..', 'lib') + "**/*.rb"].each {|file|
  3. require file
  4. include self.class.const_get(File.basename(file).gsub('.rb','').split("_").map{|ea| ea.capitalize}.to_s)
  5. }

Report this snippet  

You need to login to post a comment.