Is there a way how to require all files in lib directory at once in irb console?:

irb ( project root )
require './lib/' # not working  

structure

.
|
--lib 
  |
  |-- one.rb
  |-- two.rb
  |-- tree.rb

EDIT

I prefer a solution where I can require files only once, not each time when I start irb session.

有帮助吗?

解决方案

Create a file named .irbrc in your home directory, and write require commands for whatever file you want to require in there. When you run irb, .irbrc will be loaded.

其他提示

As described in the documentation require (and require_relative) can't take the name of a directory as argument, just a single file name. You could write something like the following to do what you want:

Dir['./lib/*.rb'].each { |f| require_relative(f) }

You can use this

Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top