-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Nycto wrote: > It would absolutely work, but it seemed like a common enough situation > that a shorthand solution might be available.
If you're a player and really want to get from: > nodeArray.findAll(function(e) { return e.hasClassName('nameOfClass'); }) to: nodeArray.findAll('hasClassName', 'nameOfClass'); you'll have to hack Enumerable. Here's an example: // after loading Prototype, apply your tweaks (separate .js file, etc): Object.extend(Enumerable, { // iterator maker - if the argument it's not a Function, // assume it's a String containing the method name iterator: function(iterator) { if (typeof iterator === 'function') return iterator; var args = Array.prototype.slice.apply(arguments, [1]); return function(value){return value[iterator].apply(value, args)}; }, // redefine 'findAll', merely by making it call "the iterator maker": findAll: function() { var results = [], iterator = this.iterator.apply(this,arguments); this.each(function(value, index) { if (iterator(value, index)) results.push(value); }); return results; } }); // apply the "new" Enumerable to all desired objects (Array, Hash, etc): Object.extend(Array.prototype, Enumerable); I know, it's pretty dirty - let's call it a proof of concept - I wouldn't recommend using it unless you heavily use this kind of filtering. Even then, maybe it's time to search for a different approach, as it surely looks like having performance problems (given Enumerable's "speed"). cheers - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD4DBQFGPmhatZHp/AYZiNkRAm0vAJUe1FxMIWPxPz9ZvooUcoYyWGgPAJ0YVACT CSxXDasRIQEypkXqQ9Qm3A== =adCB -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---