From: "T. Onoma" Date: 2004-08-23T17:15:36+09:00 Subject: Re: Callback for instance var creation? On Monday 23 August 2004 03:41 am, Robert Klemme wrote: > Methods *are* first class objects: Yes, in one sense they are. That's true. But not in the sense that they readily accessable and *carry state* (as in Python, FWIBT). That's the important missing element. > > But constants are class-level while methods are actually instance level > > (strangely enough). > > Not necessarily, see the first code example above (UnboundMethod). Note > > also that you can convert between the two types: > >> Foo.new.method( :bar ).unbind > > => # > > >> Foo.instance_method( :bar ).bind( Foo.new ) > > => # Hmm... I see more clearly now how rebinding unbound methods "reinstates" the method. But still, unbound methods seem useless. They can only be rebound to the same kind of class. Until that changes what real use are they? But perhaps in the future...(matz?) Then again I think someone did once show me an example of how unbound methods could be useful, but it was rather tricky and hence not very useful ;) Hmmm... but I do see that I might be able to finish my original proposal using them. That might work. So the constant method would be the class-level version. Oh, that might blend nicely with the capitalized methods for the instance level version --they will look identical except for the parens. Ameth - unbound Ameth() - bound Not bad. Perhaps with a little extra umph I can use that absent argument too. Maybe for bounding to a different object? [just thinking out loud here] > class Object > alias :old_method :method > def method(s) > ( @methods ||= {} )[s] ||= old_method(s) > end > end nice. a bit more concise then my version. that will work, despite the extra verbosity, method(:ameth) -or- @methods[:ameth]. thanks, T.