From: Trans Date: 2005-10-26T02:02:03+09:00 Subject: Re: Meta methods to govern meta data? Duane Johnson wrote: > I was intrigued by one of Matz's "Wild and Crazy Ideas" at RubyConf-- > the inclusion of meta data in the comments section before a method > definition. > > This got me thinking about the need for metadata and Ruby's fabulous > introspective capabilities and I wondered if it might be better to > have a governing "metamethod" for each method. Actually, more like > accessor metamethods. These metamethods would be in charge of > setting or getting key/value pairs describing things about the method > it is associated with: > > # Returns double the input > def double(i) > i * 2 > end > > meta :double, :require => 'i.is_a? Fixnum' > meta :double, :comments > => 'Returns double the input' See Facets annotation.rb. And I would urge you to call them annotations and not metadata. metadata is more apt to describing langauge reflexion and in general is too generic a terminology. > I don't quite like the syntax yet, (probably because we don't really > have a facility yet to talk about methods like this); however, I do > like the flexibility provided. Perhaps we could make a new syntax > like this: > > def double>require(i) > i.is_a? Fixnum > end > > def double>comment(original_comment) > "Haha! I can over-ride the comment." > end > > And we could even do some cool stuff like custom namespace selectors: > > def double>visibility(looking_at_me) > [Object, ActiveRecord].include? looking_at_me > end > > (i.e. the method would be called prior to any reference to 'double' > and it would return 'true' if it is visible from within the caller's > scope / namespace). > > We could even talk about meta-metamethods: > > def double>visibility>comment > "Comment for the 'double>visibility' metamethod" > end I fear more syntax. T.