是否可以递归地要求Ruby目录中的所有文件? [英] Is it possible to recursively require all files in a directory in Ruby?

查看:75
本文介绍了是否可以递归地要求Ruby目录中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个API,该API需要在其当前目录和所有子目录中加载所有.rb文件.目前,我正在为我添加的每个文件输入新的require语句,但我希望将其放置在我只需要将该文件放在子目录之一中并自动添加的位置.

I am working on an API that needs to load all of the .rb files in its current directory and all subdirectories. Currently, I am entering a new require statement for each file that I add but I would like to make it where I only have to place the file in one of the subdirectories and have it automatically added.

是否有执行此操作的标准命令?

Is there a standard command to do this?

推荐答案

在这种情况下,它会加载lib目录下的所有文件:

In this case its loading all the files under the lib directory:

Dir["#{File.dirname(__FILE__)}/lib/**/*.rb"].each { |f| load(f) }

这篇关于是否可以递归地要求Ruby目录中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆