Le 3/4/2005, "Ilias Lazaridis" <ilias / lazaridis.com> a ?crit:
>Saynatkari wrote:
>> Le 3/4/2005, "Ilias Lazaridis" <ilias / lazaridis.com> a ?crit:
>>>Csaba Henk wrote:
>>>>On 2005-04-03, Ilias Lazaridis <ilias / lazaridis.com> wrote:
>[...]
>
>>>>>but it gives me the basic idea:
>>>>>
>>>>>class Object
>>>>>  def meta() @meta ||= {} end
>>>>>end
>>>>>
>>>>>talker.sayYourName.meta[:author] = "it's just me"
>>>>>puts talker.sayYourName.meta[:author]
>>>>>=> it's just me
>>>>
>>>>If you want metadata for the _function_, then it's not exactly the way
>>>>to go.
>>>>
>>>>The sayYourName method, as defined above, is a side-effecting one,
>>>>writes out @name, then returns nil, which is a unique object, without
>>>>any reference to talker. That is, it's not a possible carrier of
>>>>metainformation.
>[...]
>
>>>I like the extracted construct - and it works in practice.
>[...]
>
>> Just to make sure there is no confusion:
>>
>> talker.sayYourName.meta[:author] = "it's just me"
>>
>> sayYourName, when evaluated, returns nil.
>
>This behaviour seems non logical.
>
>talker.sayYourName.meta
>
>talker_object->sayYourName_object->meta_object
>Class object   Method object       Hash object
>
>The sayYourName Method Object is not executed, it's just a part of the
>nested datastructure.

You are not accessing the method, you are _calling_ the method.
As mentioned earlier, talker.method(:sayYourName).meta would
work.

>> Therefore,
>> your meta structure is actually in the instance of
>> NilClass, not Talker. You should be able to test it
>> by trying nil.meta[:author] after you execute the
>> above code.
>
>yes, i've verified this (with the quick test it seemed to work).
>
>I've understood the example you give below.
>
>But I like to have the metadata directly on my function.
>
>And this without further indirection (at least not visual).

This would require changes to the parser, so I do not see
it happening at least before 2.0. On the other hand, zenspider
promised on IRC to pay $50.00 to anyone who will patch the parser
to read comments into the AST, so...

In the interim, I think a fairly robust solution would be to
just write normal offline rdoc documentation for the source
code and then write some sort of a bridge that reads the
metadata in from the rdoc and either creates a .rb file that
can be included in one's program or directly extracts the
information from rdoc at runtime.

>> You would want to follow the original example,
>> or do something like this (you can elaborate
>> on the documentation notation):
>>
>> class Object
>>   def doc(str)
>>     @doc_data ||= {}
>>     # caller[1] will be the method name doc() was called from.
>>     @doc_data[caller[1]] = str
>>   end
>> end
>>
>> class SomeClass
>>   # Some method
>>   def some_method
>>     doc "This method does something."
>>     # ...
>>   end
>> end
>
>..
>
>--
>http://lazaridis.com

E

No-one expects the Solaris POSIX implementation!