Monday, December 08, 2008

tufuhash 0.0.1 available

TufuHash is posted on github. TofuHash is a case-insensitive hash plus string/symbol indifferent access version of Ruby's Hash. It is implemented as a subclass of Hash. The behavior is easily modifiable by creating a different TofuKey. So you could have it perform key lookups anyway you want!

The current release 0.0.1 hasn't been used in many places. So if you find defects, send them to me. I'll get it fixed asap. So far I've create a bunch of unit tests to verify TofuHash behavior. These unit tests include modified versions of Ruby's Hash unit tests, sourcecode examples from the ri documentation of Hash, plus some of my own tests.

So far I've avoided monkey patching Hash. So there is a known issue where Hash doesn't always know how to handle TofuHash. For example, you can't compare Hash to TofuHash(myHash == myTofuHash), but the reverse is possible (myTofuHash == myHash).

The easiest way to create and populate a TofuHash is to use Hash's [ ] syntax as shown here:

require 'tofuhash'
h = TofuHash[ :aSymbol => "symbol", "MixedCaseString" => "string", 11 => "number" ]
puts h["asymbol"] #=> "symbol"
puts h[:mixedCaseString] #=> "string"
puts h[11] #=> "number"

color-block 0.2.0 released

Several weeks ago I made color-block available on github. This is a small library to colorize ruby output. Specifically I wanted to colorize my rake output. In some rake tasks, I didn't have access to the details of the task. So I couldn't add color to each string. Instead color-block allows me to colorize an entire block of code.

Several friends have tested color-block on Windows, Linux and Apple Mac.

require 'color-block'
include ColorBlock

color( :blue ) { "everything in this block is blue!" }

color( :white, :blue ) do
puts "now everything is white on blue!"
color( :green, :black ) { "nesting is supported" }
end

color( :white, :black, :bold ) { "third parameter to specify :bold or :dim" }