From: Sean O'Halpin Date: 2008-03-09T08:17:46+09:00 Subject: Re: fattr-1.0.2 You might also be interested in doodle (http://doodle.rubyforge.org) which I've just released. $ xmpfilter examples/foo.rb require 'rubygems' require 'doodle' class Foo < Doodle::Base has :name, :kind => String end foo = Foo "Bar" foo # => # baz = Foo 1 # ~> -:10: name must be String - got Fixnum(1) (Doodle::ValidationError) Regards, Sean On Sat, Mar 8, 2008 at 4:18 AM, Daniel Berger wrote: > > > > On Mar 7, 9:08 pm, ara howard wrote: > > NAME > > fattr.rb > > > > INSTALL > > gem install fattrs > > > > URIS > > http://codeforpeople.com/lib/ruby > > http://rubyforge.org/projects/codeforpeople/ > > http://codeforpeople.rubyforge.org/svn/ > > > > SYNOPSIS > > fattr.rb is a "fatter attr" for ruby. > > > > fattr.rb supercedes attributes.rb as that library, even though it > > added only > > one method to the global namespace, collided too frequently with > > user code - > > in particular rails' code. > > > > the implementation of fattr.rb borrows many of the best ideas from > > the > > metakoans.rb ruby quiz > > > > http://www.rubyquiz.com/quiz67.html > > > > in particular the solutions of Christian Neukirchen and Florian > > Gross along > > with concepts from the original traits.rb lib > > > > key features provided by fattrs are > > > > - ability to specify default values for attrs and definition > > time. values > > can be literal objects or blocks, which are evaluated in the > > context of > > self to initialize the variable > > > > - classes remember which fattrs they've defined and this > > information is > > available to client code > > > > - a whole suite of methods is defined by calls to #fattrs including > > getter, setter, query (var?) and banger (var! - which forces > > re-initialization from the default value/block) > > > > - ability to define multiple fattrs at once using key => value > > pairs > > > > - fast lookup of whether or not a class has defined a certain fattr > > > > - fattrs can be defined on objects on a per singleton basis > > > > - getters acts as setters if an argument is given to them > > > > - block caching, calling an fattr with a block sets the instance > > variable to that block > > > > - shortcuts for adding class/module level fattrs > > > > Interesting. What about data types? > > class C > fattr 'a' => Integer > end > > c = C.new > c.a = 42 # ok > c.a = 'hello' # TypeError > > You may have this, but I didn't see it in the samples or readme (but > very well may have missed it). > > Regards, > > Dan > >