#wrap is simply amazing. We can easily augment Class.create to make
all of instance methods fire proper events ( e.g. "Class:method" )
Class.create = Class.create.wrap(function() {
var args = $A(arguments),
proceed = args.shift(),
methods = args.last(),
className = methods['className'] || 'Klass';
for (var m in methods) {
if (/initialize|className/.test(m)) continue;
methods[m] = methods[m].wrap(function() {
var _args = $A(arguments), _proceed = _args.shift();
console.log(className + ':' + m);
return _proceed.apply(_proceed, _args);
})
}
return proceed.apply(proceed, args);
})
var Class1 = Class.create({
initialize: function() { },
className: 'Class1',
bar: function() { }
});
var Class2 = Class.create({
initialize: function() { },
className: 'Class2',
baz: function() { }
});
new Class1().bar(); // fires "Class1:bar"
new Class2().baz(); // fires "Class2:baz"
P.S. This is by no means a thorough solution, but rather a proof of
concept...
Best,
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---