On Mar 31, 2005, at 3:44 AM, Ilias Lazaridis wrote:

>>> Is there a standard way to apply metadata/annotations to my class 
>>> Talker, its Methods, its Attributes?
>>>
>>> E.g.:
>>>
>>> class Talker
>>>
>>>   attr_accessor :name # Type = String; Label = Name; Size = 30;
>>>   attr_accessor :age  # Type = int;    Label = Age;  Min=1; Max=150;
>>>
>>>   def sayYourName
>>>   end
>>> end
>> Your comment has already hit on one solution.  :)  There may be many 
>> others, depending on how you intend to use this information...
>
> I extract: Ruby has not standard-mechanism for metadata/annotations.
>
> ok

Correct, but it certainly provides ample tools to build whatever you 
need.

This aspect you've just hit on is the very essence of programming, in 
my opinion.  No language provides everything for every need.  The 
processes of adapting your chosen language to the problem space is the 
craft.

> Where can I find the implementation of "attr_accessor"?
>
> I'm intrested in seeing how much effort it is to write an own 
> "flex_attr_accessor".

I'm sure attr_accessor is defined in the Ruby source.  Here's my 
version of a pure Ruby class accessor:

irb(main):015:0> class Module
irb(main):016:1> def cattr_accessor( *symbols )
irb(main):017:2>    symbols.each do |sym|
irb(main):018:3*        class_eval "def self.#{sym}(  ) @@#{sym} end
irb(main):019:3"                    def self.#{sym}=( value ) @@#{sym} 
= value end"
irb(main):020:3>    end
irb(main):021:2> end
irb(main):022:1> end
=> nil
irb(main):023:0> class Accessor
irb(main):024:1> cattr_accessor :one, :two
irb(main):025:1> def self.fetch_one(  )
irb(main):026:2>     @@one
irb(main):027:2> end
irb(main):028:1> end
=> nil
irb(main):029:0> Accessor.one = "James"
=> "James"
irb(main):030:0> Accessor.two = "Gray"
=> "Gray"
irb(main):031:0> Accessor.one
=> "James"
irb(main):032:0> Accessor.two
=> "Gray"
irb(main):033:0> Accessor.fetch_one
=> "James"

Hope that helps.

James Edward Gray II