I've reviewed a little the documentation, but find nothing about
metadata.
Probably because it's too general a topic. The word "metadata" changes
meaning by context.
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...
-
"attr_accessor" does not work on class variables (e.g. @@count).
Must I create @@var/getter/setter manually?
Not exactly. Here's a trick:
irb(main):001:0> class MyClass
irb(main):002:1> class << self
irb(main):003:2> attr_accessor :test
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> MyClass.test = 501
=> 501
irb(main):007:0> MyClass.test
=> 501
There is a gotcha though:
irb(main):008:0> class MyClass
irb(main):009:1> def test_method
irb(main):010:2> @@test
irb(main):011:2> end
irb(main):012:1> end
=> nil
irb(main):013:0> MyClass.new.test_method
NameError: uninitialized class variable @@test in MyClass
from (irb):10:in `test_method'
from (irb):14
from :0
You can see that this technique does not use @@test.
All of this is just playing around though. If you seriously need to
define class accessors a lot and can't be bothered to type:
def self.test( ) @@test end
def self.test=( value ) @@test = value end
Most editors I've ever seen will allow you to macro that and assign it
to a single keystroke.
My opinion, feel free to completely ignore, is that you've strayed
pretty far from "evaluating Ruby" when you worry about details like
this. We can sit here and show you examples like the above
indefinitely, exploring all corners of the language. There's no
substitute for just learning the language and seeing what it can do for
you though, and this is a poor way to go about that.
James Edward Gray II