The Facets gem is fairly popular, and for good reason. I was poking through the documentation on the plane home from Chicago (I have a contract position there for the next month) and found a couple of neat things to share:

Facets library

  • Autoarray class—an Array that autovivifies any number of dimensions. For example:a = Autoarray.new
    a[3][4][5] = 1
    would create a 3-dimensional array with values initialized to ‘nil’ and the appropriate cell set to 1.
  • Dictionary class—a Hash that retains order. The order, by default, is whatever order its contents were given in; however, it can also enforce any arbitrary ordering that you provide.
  • Enumerable extensions—a (very nice) module that extends the Enumerable mixin. It’s huge! There are so many idioms captured in this that I can’t explain them all. But if you like Ruby for it’s concise syntax and easy chaining of things like ‘each’, ‘map’ and ’select’, you’ll like what you see in here.
  • File.rewrite—open, modify, write back to disk, all in a single ruby block.
  • FileUtils.head and FileUtils.tail—handy functions that let you get at the first few or last few lines of a file.

There’s plenty more to look at in the Facets gem… these are just a few that caught my attention. Install the gem and then use “gem server” to check out the documentation ;)