From: "Hal E. Fulton" Date: 2003-05-22T07:59:15+09:00 Subject: Re: How I'd like method-wrapping to work... ----- Original Message ----- From: "Robert" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Wednesday, May 21, 2003 5:39 PM Subject: Re: How I'd like method-wrapping to work... > That's no fantasy. Dreams come true... The plane, the plane! (Sorry, showing my age...) (For non-Americans and/or people under 35: A reference to the TV show _Fantasy Island_.) Thanks for this fascinating reply... > > 3. I've probably overlooked a lot of issues. Please > > educate me (Matz, Guy, Dave, David, others...) > Although not listed this bugged me. See what I came up with (attached). Not listed? :) others.include?(Robert) # true > Cons: > - 'this' had to be introduced since I found no way to > rebind the proc (even if there were a way we had > to deal with multiple concurrent invocations). The > deeper reason for this problem is, that the block > comes into existence in class context but should be > evaluated in instance context later. I was having a hard time with that, too, and I wasn't even worrying about threads. > - Argument lists have to be doubled for the block Hmm, not sure what you mean here. But I am going to play with this a little. > Pros: > - It nearly looks like what you asked for. > - Return values work reasonably. By "reasonably" do you mean that the return value of prior will be used even if that call is not the last one inside the hook block? Ideally we shouldn't have to do the "val" stuff that I do. I'll test. > - It even works for nested invocations, i.e. recursion > - It works with several instances in the call chain This is essential if I understand you rightly. It's also one reason we need this -- methods are sometimes aliased more than once, e.g., in a library and in your own code. > - You can exactly do what you put in So I can! I see that the code in hook_test is line for line the same as mine. However, on 1.7.3 on Windows I got a syntax error on line 40 of hooks.rb (had to remove the "proc &"). Not sure what the issue is here -- assume it worked for you that way? Thanks for a quick reply... this is another bit of code that I'll certainly save. I do hope the discussion continues, though... Cheers, Hal