I wrote this little script yesterday and was very happy with it and wanted to share. Hopefully someone else out there finds it useful.
Usually when I write classes (Prototype 1.6) I use what I think is a pretty common method for defining defaults and allowing those defaults to be overridden. It looks something like this: http://pastie.caboo.se/108865 (Section 1) This simply and quick solution usually does the job. But notice how the "defaults" object has an object within it called "feedback". This object holds 3 items called "tryAgain", "correct", and "incorrect". What if you want to override the "correct" item but leave the "tryAgain" and "incorrect" intact? The standard "Object.extend" method isn't going to help us here. Setting only the "feedback.correct" will in fact leave you with no "feedback.tryAgain" or "feedback.incorrect" properties at all. They'll be overridden and lost. http://pastie.caboo.se/108865 (Section 2) My solution was to write a mixin that would recursively look at the passed in properties and only replace the exact nodes specified. For example, now we can override the "correct" item AND leave the "tryAgain" and "incorrect" intact! http://pastie.caboo.se/108865 (Section 3) I tried to write this mixin in such may that it could be used on just about any Class. I have not extensively tested it but it's holding up so far in all of my cases. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
