Is there a way to load files that only match a specific string? For example, suppose I want to load files that matches account1.rb
account2.rb
and so on. I want to be able to do something like
require File.expand_path("../account*.rb", __FILE__)
but of course this does not work. What is the best way to do this?
You can do the same thing with a loop:
Dir.glob(File.expand_path("../account*.rb", __FILE__)).each do |file|
require file
end
The expand_path
method only resolves paths. It does not expand wildcards.
I tried to use this to create a test-suite for Minitest without using Rspec. The accepted answer didn't work for me, but this did:
require "minitest/autorun"
Dir.glob("*_test.rb").each do |file|
require_relative file
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With