Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby extension mechanism that plays nice with class reloading

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 nanoboy.gemspec
README.md

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?

Something went wrong with that request. Please try again.