I just released a gem I’ve been working on for the last couple days. It’s called Naught and it’s intended to make it easy to build various kinds of Null Object class in Ruby.
This isn’t the first generic Ruby Null Object library, but I think you’ll find its approach a little different than most. Rather than a one-size-fits-all solution, Naught gives you tools to quickly build the null objects that make sense for your library or app. It also includes some less-common features, such as:
- The ability to “mimic” or “impersonate” specific classes. The resulting null object has a stubbed version of the target class’ interface; any other messages sent to it are errors.
- Traceable null objects that can remember where they were instantiated, for easier debugging.
- The option to have null objects implement sensible default versions of
#to_ary, etc.—all the usual explicit and implicit conversion methods.
- Convenient conversion functions like
Actual(). See the documentation for examples.
- And quite a bit more…
The README is fairly detailed, check it out for more about the what, they why and the how.