What you need is to find the files on your path which match the pattern *_file.rb
.
To do that, use the globbing from Dir
class in Ruby.
matched_files = Dir['/path/to/folder/*_file.rb']
#=> ['/path/to/folder/main_file.rb', '/path/to/folder/sub_file.rb', '/path/to/folder/foo_file.rb']
Now, you can extract the basename by iterating over those files:
base_files = matched_files.map { |file| File.basename(file) }
#=> ['main_file.rb', 'sub_file.rb', 'foo_file.rb']
Additionally, if you just want to extract main, sub, foo from that, you can match against the pattern to do that as:
base_files.map { |file| file.match(/(.*)_file.rb/)[1] }
#=> ['main', 'sub', 'foo']
With the files name collected, you can check those names against your conditionals to execute whatever is meant for that file..
Good luck.