I am trying to require
all the projects from the projects
and sub_projects
folders.
Dir Structure:
|-- project_manager
-- run_farm.rb
-- projects
-- build_coop.rb
-- sub_projects
-- count_apples.rb
-- count_chickens.rb
I found this answer but was unable to get it to work: Best way to require all files from a directory in ruby?
Original syntax from the link: Dir["/path/to/directory/*.rb"].each {|file| require file }
So, in run_farm.rb, I tried this:
path_to_directory = File.dirname(File.absolute_path(__FILE__))
Dir[path_to_directory + '/projects/**/*'].each { |file| require file }
Also tried:
path_to_directory = File.dirname(File.absolute_path(__FILE__))
Dir[path_to_directory + '/projects/**/*'].each { |file| require "#{file}" }
When I run run_farm.rb
, I get this error: .rbenv/versions/2.6.6/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
I was able to run this, so I know something works:
path_to_directory = File.dirname(File.absolute_path(__FILE__))
Dir[path_to_directory + '/projects/**/*'].each { |file| puts "#{file}" }
Found this but it didn't help me: https://github.com/rbenv/rbenv/issues/1158
I hope I provided enough info. Does anyone know what I am doing wrong?