From: "Hal E. Fulton" Date: 2003-05-22T02:59:33+09:00 Subject: How I'd like method-wrapping to work... OK, I read Matz's blog entries as well as I could. One thing that occurs to me is that I don't really want to distinguish between "before" and "after" in an artificial way. Here's my tentative dream of how I'd like to do this kind of thing in Ruby. (I'm using the keyword 'prior' for lack of anything better right now.) class String define_hook(:length) do puts "I'm calculating the length" prior end define_hook(:upcase) do val = prior puts "I just did an upcase operation" val end define_hook(:reverse) do puts "I'm about to do a reverse operation" val = prior puts "I just did a reverse" val end end str = "abcde" x = str.length puts x y = str.upcase puts y z = str.reverse puts z # Output: # I'm calculating the length # 5 # I just did an upcase operation # ABCDE # I'm about to do a reverse operation # I just did a reverse # edcba Notes: 1. Obviously parameter-passing needs to be addressed. 2. It would be nice to get around the return-value problem (where have I seen this before? 'ensure'?) 3. I've probably overlooked a lot of issues. Please educate me (Matz, Guy, Dave, David, others...) ")".intern Hal