Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
[ANN] Defaultable 0.0.3
John W. Long
5/4/2005 3:46:00 AM
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/defa...
Tests:
http://johnwlong.com/downloads/iblp-mixins-0.0.3/test/unit/defaultab...
Defaultable is currently part of another small project which can be
downloaded here:
http://johnwlong.com/downloads/iblp-mixins...
--
John Long
http://wiseheart...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
[ANN] Defaultable 0.0.3
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password