Alpha
Alpha

Reputation: 14026

Run ruby files through script

I want to run all ruby files from specific folder(without using Rake gem)(I'm trying this only for learning purpose). In order to achieve that, I did following:

files = Dir[File.join(Dir.pwd, "tests/*.rb")]

files.each do |file|
  ruby file
end

when I run above script, it throw an error:

run.rb:13:in `block in <main>': undefined method `ruby' for main:Object (NoMethodError)

I've ruby installed on my machine. Please suggest change in my code to work it.

Upvotes: 2

Views: 87

Answers (1)

Damien MATHIEU
Damien MATHIEU

Reputation: 32629

There is no ruby method inside ruby programs.
You're using ruby in your terminal because that's the name of the executable, not the name of a function.

You can use require to do what you're trying to achieve.

files = Dir[File.join(Dir.pwd, "tests/*.rb")]

files.each do |file|
  require file
end

Upvotes: 2

Related Questions