C
Csaba Henk
The Ruby Object Model does not contain reflective MetaClasses, which
would enable to apply metadata even to methods.
You can attach metadata to a certain method object, it's just not what
you will want. Why? Because you refer to a method via the object to which
it belongs, and this always give you a fresh objectification of the
method, as we have discussed.
But. If you stick to refer to methods via their carrier objects (which
you seem to do, and which seems to make sense), then why can't you just
use the object itself as the basic reference point, without further
considerations? Why would be talker.meta[:sayYourName] worse (in any
sense) than what the (disfunctional) talker.methodsayYourName) could
be?
I mean, the certain object gives the namespace via which you can access
the method as an object. Then why not use the same namespace for storing
the metainformation of the method (without any bitterness)?
Even better, you could make the class or module carry the
metainformation, to which the method belongs as an instance method (each
method is registered as an instance method of some class or module --
singleton methods of an object are instance methods of the metaclass of
the object [accessible as in
class << "a"; self; end
and it is a permanent object, unlike methods]).
This has the advantage that method objects then determine their proposed
metainformation, as they hold a reference to the class/module to which
they belong as an instance method. Alas, in present ruby you can't get
this information explicitly, and now if you say it's a flaw in Ruby, I'd
say I agree (although one which doesn't seem to cause great problems).
For example,
[1].methodat).inspect
gives the string "#<Method: Array#at>", but there is no method of the
method object [1].methodat) which would give you Array, the class. In
this particular case, as a clumsy workaround, you could parse out Array
from the above string, but this won't work if the method in question
belongs to an anonymous class (like objects' metaclasses).
Huh, I hope it's not too messy.
Csaba