From: Charlie Bowman Date: 2006-03-03T00:53:09+09:00 Subject: Re: cleaner Ruby in a rails view --=-ok629ACj2M8gOTQiv+nt Content-Type: text/plain Content-Transfer-Encoding: 7bit I'm not so sure. I've been using perls Template-Toolkit for the last several years and I love the fact that my template doesn't care weather or not I actually passed it a variable. It allows me to avoid all the problems that rails users (me included ) keep having. I try to re-use my views with as many actions as possible, and this creates a lot of rescue nil code. Maybe it's just personal preference or maybe I'm just used to TT but I definitely would rather have my views just skip over any nil values than throw an error. On Fri, 2006-03-03 at 00:43 +0900, James Edward Gray II wrote: > On Mar 2, 2006, at 9:33 AM, Charlie Bowman wrote: > > > I know this is the ruby list and not the rails list but it would be > > nice > > if we didn't have to add code to our views to rescue nils. I guess > > you > > could add the method each if you to the nil class right? > > You can, sure. Whether or not it is a good idea is the question. ;) > > Currently, when you call each() on nil, it explodes. This is a good > thing, because it takes you right to the problem. You were expecting > to have an Enumerable, but you really have a nil. > > If we take that away, Ruby will start silently accepting what are > most likely mistakes. While that may keep you from typing (enum || > []).each... in some places, it will prevent Ruby from catching real > errors in others. Better that we explicitly state that nil is okay > in this case, and let Ruby watch our back for us the rest of the > time, don't you think? > > James Edward Gray II > Charlie Bowman http://www.recentrambles.com --=-ok629ACj2M8gOTQiv+nt--