From: Ara.T.Howard@... Date: 2005-05-04T12:04:49+09:00 Subject: Re: [ANN] traits-0.0.0 On Tue, 3 May 2005, Kevin Howe wrote: > Very cool, this is along the lines of something I've been toying with for > the next version of Nemo (rubyforge.org/projects/nemo). Nemo tags class > attributes (traits) with display-related metadata, then later uses it to > render an html table or html edit form. The trait version might look > something like this: > > class Foo > mtrait :name, :label=>'Full Name', :required=>true > mtrait :birthday, :type=>:date, :required=>true > end > > foo = Foo.new > foo.name = 'Joe' > foo.birthday = Date.today > > Editor.new(foo).render > > This would display an html form with two required text fields labelled "Full > Name" and "Birthday". Hitting the save button updates the object instance > with the given input, assuming it passes all validations. so mtrait would be a wrapper on trait? > I've been wanting to abstract out the metadata definition into a generic > mechanism for defining metadata on any attribute, but if this were added to > traits that would pretty much be it. Thoughts? you would want something like class Foo trait 'a', 'description' => 'metadata', 'fu' => 'bar' end p Foo::trait_opts('a') that'd be possible. or did you mean something else? > Also, how does trains handle inheritance? Let's say we have A < B, then B > adds a few more traits, will A's @__trait data remain unaffected? it handles it. it's __very__ tricky however since - can't use @@var since derived classes will clobber - can't use @var since each class will simply have own so instead it uses @vars with a search_path up ancestors. this turns out to be kinda tricky in the general case.... eg. jib:~/eg/ruby > cat a.rb require 'traits' class A trait 'a' end p A::traits class B < A trait 'b' end p B::traits p A::traits jib:~/eg/ruby > ruby a.rb [["a"], ["a="]] [["b", "a"], ["b=", "a="]] [["a"], ["a="]] cheers -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================