Would’nt make more sense to have just a singleton method object
referring to the same method ?
My real problem is attaching some metadata to a method, allowing it to
be retrieved at any time, somehow like MetaTags does
(yet not looked at it’s code, but IIRc it uses a big class level hash
collecting all the metainformations) some suggestions ?
Would’nt make more sense to have just a singleton method object
referring to the same method ?
My real problem is attaching some metadata to a method, allowing it to
be retrieved at any time, somehow like MetaTags does
(yet not looked at it’s code, but IIRc it uses a big class level hash
collecting all the metainformations) some suggestions ?
We had this discussion some weeks ago, when someone else posted a quite
similar question (method as hash key). AFAIR Matz wanted to consider
changing #hash and #eql so Method instances can be reasonably used as hash
keys.
Singletons might have some drawbacks that he does not want to pay the
price for. The major issue is that they have to be stored somewhere and
thus take up mem even when they are no longer used. Making Method hash
key compatible is completely sufficient IMHO.
We had this discussion some weeks ago, when someone else posted a quite
similar question (method as hash key). AFAIR Matz wanted to consider
changing #hash and #eql so Method instances can be reasonably used as hash
keys.
this makes sense, but is not what I need.
I wanted to add stuff to a method object (namely a is_a_test_method?
method), and be able to access the same method later and check if it
has that property (if it responds to is_a_test_method?)
Note that I needed it just for some little playing (copying the
examples from the article at onjava.com about annotations in java 1.5)
so I won’t bother if I can’t have it
Singletons might have some drawbacks that he does not want to pay the
price for. The major issue is that they have to be stored somewhere and
thus take up mem even when they are no longer used. Making Method hash
key compatible is completely sufficient IMHO.
Yes I see what you mean. thanks for the answer.
···
il Fri, 23 Apr 2004 14:45:18 +0200, “Robert Klemme” bob.news@gmx.net ha scritto::
this makes sense, but is not what I need.
I wanted to add stuff to a method object (namely a is_a_test_method?
method), and be able to access the same method later and check if it
has that property (if it responds to is_a_test_method?)
I see two possibilities:
you either
access the method repeatedly using the symbol: in that case you can
store the information in a hash somewhere (say a hash in the singleton
class of the object), using the method name as the key
keep the Method or UnboundMethod (if using instance_method) objects
around; then you can add that info to the object itself directly,
using its instance vars + singleton methods.
Note that I needed it just for some little playing (copying the
examples from the article at onjava.com about annotations in java 1.5)
so I won’t bother if I can’t have it
Per-method annotations as shown in
can be implemented trivially using Module#method_added (it’s the same
technique used commonly to implement docstrings).
btw,
···
On Fri, Apr 23, 2004 at 10:44:03PM +0900, gabriele renzi wrote:
–
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
On a normal ascii line, the only safe condition to detect is a ‘BREAK’
everything else having been assigned functions by Gnu EMACS.
– Tarl Neustaedter
access the method repeatedly using the symbol: in that case you can
store the information in a hash somewhere (say a hash in the singleton
class of the object), using the method name as the key
just done this
keep the Method or UnboundMethod (if using instance_method) objects
around; then you can add that info to the object itself directly,
using its instance vars + singleton methods.
yes, but the logical place to hold this is an hash so you go back to #1
Note that I needed it just for some little playing (copying the
examples from the article at onjava.com about annotations in java 1.5)
so I won’t bother if I can’t have it
Per-method annotations as shown in Radar – O’Reilly
can be implemented trivially using Module#method_added (it’s the same
technique used commonly to implement docstrings).
exactly what I did
···
il Fri, 23 Apr 2004 23:28:19 +0900, Mauricio Fernández batsman.geo@yahoo.com ha scritto::