Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top