Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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 }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top