Skip to content

bfcapell/nanoboy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nanoboy

nanoboy is a little ruby gem that allows you to extend classes and/or modules with several advantages over the usual ruby include/extend:

  • lazy extension -- the extended class is not loaded if it's not already in the memory. The extension will be applied once the class is loaded.
  • persistent on class reloading -- if you are developing in Rails, where classes are reloaded on each request, use nanoboy and forget about reloading problems and callbacks.

Due to the lazy extension feature, this gem is specially useful when you have loading order problems. For example, if you are extending a lib that is extending another lib. Yes, these things happen.

Syntax

There are two possible syntaxes:

  • Explicit
Nanoboy.include! :ClassToExtend, MyAwesomeModule
  • Sugared
:ClassToExtend.include! MyAwesomeModule

Note that the class to be extended is named with its symbol, not the constant. If you use the constant, it gets loaded and you lose.

And yes it works with namespaces too:

:"CrazyModule::ClassToExtend".include! MyAwesomeModule

About the name

As @jondeandres said, if there is a well-known gem called FactoryGirl, what's the problem with Nanoboy?

About

A Ruby extension mechanism that plays nice with class reloading

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages