문제

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