"Its Me" <itsme213 / hotmail.com> schrieb im Newsbeitrag news:x8s%b.4637$OH4.695 / fe2.texas.rr.com... > "gabriele renzi" <surrender_it / remove.yahoo.it> wrote > > look on RAA for 'metatags' > > Thanks, but this is very oriented towards documentation strings. I am > looking for something that operates at the meta-level, adding and removing > interlinked structures to classes, methods, ... This is roughly the change > from Javadoc tags to Java 1.5's metadata annotations (or, equivalently, to > C# metadata attributes). > > My very preliminary thoughts are along these lines: > module Meta > # meta allows adding and removing arbitrary properties > def meta .... end > end > > class Method # perhaps I need to use UnboundMethod? > include Meta > end > > class Parameter # I would like this but it seems impossible to hook into > include Meta > end > > class Attribute > # one instance of this for each attribute > # Ruby does not have such a class, so I would build my own versions of > attr: or attr_accessor: > include Meta > end > > class Class > include Meta > end > > And then use this: > class Mine; end meta ... # metadata on Mine I don't think this will work since class...end doesn't return the class. > class Mine > def foo; end meta ... # metadata on Mine#foo > end > > Thoughts? Am I trying to do something ridiculous? How about this: class Module def meta(*args) case args.size when 0 meta_data[self] when 1 if args[0].kind_of? Hash meta_data[self].update args[0] else meta_data[args[0]] end when 2 meta_data[args[0]].update args[1] else raise ArgumentError, "Wrong number of args" end end def meta_data @meta ||= Hash.new {|h,k| h[k] = {}} end end class Foo def foo; puts "bar"; end meta :foo, "method" => "metadata", "foo" => "bar" meta "class" => "metadata", "foo" => "bar" end p Foo.meta :foo p Foo.meta robert