From: Joel VanderWerf Date: 2005-01-09T03:28:49+09:00 Subject: Re: Seeking info on keyword parameters Stefan Lang wrote: > That reminds me a bit of C# attributes. Attributes are > available to reflection and can be attached to methods, classes > and other type definitions. > > So one can write: > [ConditionalAttribute("DEBUG")] > void debug_method(string msg) > { > .... > } > > to tell the compiler, development tools and other > developers that this method is intended for debugging. > (One effect of the example above is, that the C# compiler > compiles the method only if the DEBUG symbol is set.) > > New attributes can be defined like classes, so you > can attach any meta data you like to classes, methods etc. > > I think this could be useful for Ruby too. > Could be done... $meta = {} def meta_set(tag, obj=self) case obj when Symbol # designates a method $meta[instance_method(obj)] = tag when Module $meta[obj] = tag else # ... end end module M meta_set("a module") class C meta_set("a class") def foo; end meta_set("a method", :foo) end end p $meta __END__ Output: {M=>"a module", #=>"a method", M::C=>"a class"}