Ruby 'require'

working on a ruby project with several files all lumped into a single
subdirectory. I would like to organize it more logically by grouping
files that share the same functionality. For example instead of

   main.rb
   allfiles << subdir
     afile
     bfile
     cfile
     dfile

would like reorganize these into

  main.rb
  allfiles << subdir
    func1 << subdir
     afile
     bfile
   func2 << subdir
     cfile
     dfile

Any trick i can use to simply pulling these files into main.rb. So
instead of

   require 'allfiles/func1/afile'
   .
   .
   .
   require 'allfiles/func2/dfile'

i would like to use a more simplified require instead of enumerating
each of the files.

···

--
Posted via http://www.ruby-forum.com/.

John

···

On Fri, Jul 29, 2011 at 1:00 PM, Rick Tan <bellcolt@hotmail.com> wrote:

working on a ruby project with several files all lumped into a single
subdirectory. I would like to organize it more logically by grouping
files that share the same functionality. For example instead of

Personally, I've grown to like explicit requiring, but if you're sure you
want to require all the files in the subdirs into main, you could use a
glob.

Dir["#{File.dirname __FILE__}/**/*.rb"].each { |filename| require filename }

···

On Fri, Jul 29, 2011 at 3:00 PM, Rick Tan <bellcolt@hotmail.com> wrote:

working on a ruby project with several files all lumped into a single
subdirectory. I would like to organize it more logically by grouping
files that share the same functionality. For example instead of

  main.rb
  allfiles << subdir
    afile
    bfile
    cfile
    dfile

would like reorganize these into

main.rb
allfiles << subdir
   func1 << subdir
    afile
    bfile
  func2 << subdir
    cfile
    dfile

Any trick i can use to simply pulling these files into main.rb. So
instead of

  require 'allfiles/func1/afile'
  .
  .
  .
  require 'allfiles/func2/dfile'

i would like to use a more simplified require instead of enumerating
each of the files.

--
Posted via http://www.ruby-forum.com/\.

Use аutomatic Class Loader and forget about the :require :wink:

http://ruby-lang.info/blog/class-loader-finds-and-loads-classes-for-your-app

···

--
Posted via http://www.ruby-forum.com/.