From: "John W. Long" Date: 2005-05-04T12:45:56+09:00 Subject: [ANN] Defaultable 0.0.3 This is the first public release of a very small project I've been working on recently. It's very similar actually to Ara.T.Howard's implementation of Traits. The goal of the project is to provide a mixin for objects that adds a series custom attribute methods for default values: require 'defaultable' class TestObject include Defaultable default_accessor :test => 'Hello world!' end o = TestObject.new puts o.test #=> 'Hello world!' If the object's constructor has a hash as the last parameter it assumes it's an options hash and automatically extracts values for the object from it: class TestObject def initialize(options = {}) end end o = TestObject.new(:test => 'Cool beans!') puts o.test #=> 'Cool beans!' The current implementation also works well with inheritance allowing inherited objects to inherit their parent object's attribute defaults. I'm particularly interested in feedback on the implementation. I'm not a metaclass guru, so for those of you who are, I would especially appreciate feedback on the class methods "included" and "method_added" on the module. These methods are currently hacks to make it useful, but their implementation isn't pretty. Download: http://johnwlong.com/downloads/iblp-mixins-0.0.3/lib/defaultable.rb Tests: http://johnwlong.com/downloads/iblp-mixins-0.0.3/test/unit/defaultable_test.rb Defaultable is currently part of another small project which can be downloaded here: http://johnwlong.com/downloads/iblp-mixins-0.0.3.tgz -- John Long http://wiseheartdesign.com