From: Peter Ehrlich Date: 2011-05-02T12:17:09+09:00 Subject: Re: update variables based on own value - critique please? Hey Josh! Thanks for the detailed answer. What you say makes sense for extending object -- it is not an action to be taken lightly. I will see to using mixins or finding other places to keep the code. I think I find myself agreeing with all of your philosophies, but then see this as example of that philosophy put in to practice, not otherwise. This was my striving to make code self commenting and DRY. Thats why I create the lambdas, so that they have names, so that they can be read. Thats why they are in this function, and thats why its simplified for readability - the point of the method is really really trying to stay simple, so that someone doesn't come along later and make it complicated. Yes the code I add is not insignificant, and yes its a new way of doing things when an old way would have done just as well. But this is what made rails great! Without this thinking, we would have no capitalize method or the other numerous rails helpers. I'm trying to imitate THAT style. Sure, if you count the changes, that is more. But that is simple minded. Lines should be counted not as what was written but as what must be maintained in the future. My hope is that the Object extension remains simple and never must be touched again, which makes this code shorter. And even if my json viewing code takes more lines, that's ok, because the code is simpler. Here there is the perfect point-in-case. In my 'before' example I made not one but two typos (which you pointed out), and led the reader to futher wonder if quoted string were really required. (It turns out they were but didn't have to be, and we see our first refactor already requiring changes in EVERY key.) I, like many, have the blessing and the curse of reading very quickly; it took me several rereads to find the errors you pointed out, and those errors would have had the potential to stump me thoroughly upon an exception. @Thomas. I wish I could answer that, but I can't really be sure I'm picturing what you are. Were you thinking methods in view helpers file? Or in the model? Or defined exactly where the lambdas are? (in latter case, there's no effective difference) Whatever the case, I'm trying to keep as much as possible out of the larger namespace as much as possible here -- that is, unless there is elsewhere they may be needed. Thanks all, --Peter -- Posted via http://www.ruby-forum.com/.