Skip to content

burnt43/ruby-lazy-const

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruby-lazy-const

Description

Automagically lazily load constants without having to explicitly require the files they are located in.

Tutorial

Require the gem:

require 'ruby-lazy-const'

Set the base directory where all your ruby files are:

LazyConst::Config.base_dir = '/home/foobar/ruby_project/lib'

This gem will now automatically find the file where the const is located in as long as you follow convention for filenames and ruby const names.

Suppose you have some files:

lib/foo.rb

class Foo
end

lib/bar.rb

module Bar
end

lib/bar/qux.rb

module Bar
  class Qux
  end
end

As long as you set LazyConst::Config.base_dir correctly, then when you have a constant that is not yet loaded into Ruby, it will find it.

Foo # This const is not defined, so we will load it from lib/foo.rb
Bar # This const is not defined, so we will load it from lib/bar.rb
Bar::Qux # This const is not defined, so we will load it from lib/bar/qux.rb

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages