gem - Odd behavior from Ruby's require -


i'm writing ruby gem lots of nested classes , such. i'd keep huge list of require statements out of main ruby file in /lib directory, instead used following:

dir[ file.join( file.dirname(__file__), "**", "*.rb" ) ].each {|f| require f} 

which totally worked fine until morning when added new file (helper module) , library acting file isn't loaded, though is. checked with

puts "loaded" if defined?(realtimearghelpers) 

i duplicated require statement check see if new file getting returned

dir[ file.join( file.dirname(__file__), "**", "*.rb" ) ].each {|f| puts f} 

and is. have manually require 1 file. out of nowhere. have 101 other files being gathered statement , works fine. not 1 file. don't have name conflicts besides

/path/arg_helpers.rb /path/realtime/agents.rb /path/realtime/queues.rb /path/realtime.rb /path/realtime_arg_helpers.rb 

which still shouldn't 'conflict.' i'm baffled seemingly random behavior, unless i'm doing illegal in language. tried renaming module, renaming file, no dice. why 1 file not getting loaded?

the problem comes way require works in ruby. whenever file required (let's consider case of .rb source file keep simple), ruby parses file , executes instructions not in methods. if use classes defined in files yet loaded, ruby won't find them.

i don't know if there recommended way used gem authors deal that, coming c/c++ background tend favour explicitly requiring dependencies in each source file, rather trying maintain giant sorted list in main.rb (or equivalent).


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -