Thanks for the reply. That looks like an interesting route of handling
events, but
not exactly what I had in mind. Ideally I would like to be able to
just use Event#observe
and Event#fire. It might be workable using wrap, but that would add a
whole other
layer of complexity that I hope to avoid.
Thanks,
Keith
On Mar 2, 5:16 am, kangax <[EMAIL PROTECTED]> wrote:
> #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
-~----------~----~----~----~------~----~------~--~---