Dynamically include all modules in a directory

/ Published in: Ruby
Save to your folder(s)

This assumes the modules names are CamelCase and not UPPERCASE.

Copy this code and paste it in your HTML
  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. }

URL: www.rubyslacker.com

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.