Meta-Meta-Programming, revisited

Not sure how the method_name parameter is useful, isn’t it
just :description? In any case, the paraemters are nicely
intuitive!

post_condition (like pre_condition) receives *method_names. So,
passing the name of the wrapped method might be usefull.

Hey, wrap_method doesn’t receive *method_names… yet… ;]

gegroet,
Erik V. - http://www.erikveen.dds.nl/


class Module

def wrap_method(method_name, &block1)
|
wrappping_block.call(old, args2, block2, self)
|
end

def pre_condition(*method_names, &block1)
method_names.flatten.each do |method_name|
wrap_method(method_name) do |org_method, args2, block2, obj2|
block1.call(obj2, method_name, args2, block2)

     org_method.call(*args2, &block2)        if org_method
   end
 end

end

def post_condition(*method_names, &block1)
method_names.flatten.each do |method_name|
wrap_method(method_name) do |org_method, args2, block2, obj2|
org_method.call(*args2, &block2) if org_method

     block1.call(obj2, method_name, args2, block2)
   end
 end

end

end

What about |obj, method_name, args, block|? That one must
be easy to remember, since it resembles the order of the
call (object is the receiver).

Changed. [1]

Hey, wrap_method doesn’t receive *method_names… yet… ;]

Fixed. [2]

I changed the internals of wrap_module slightly, but enough to
be measurably faster… [2]

The implementation of “once” is now thread safe. [3]

gegroet,
Erik V. - http://www.erikveen.dds.nl/

[1] http://www.erikveen.dds.nl/monitorfunctions/index.html#4.0.0
[2] http://www.erikveen.dds.nl/monitorfunctions/index.html#5.2.0
[3] http://www.erikveen.dds.nl/monitorfunctions/index.html#6.3.0

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs