From: Ryan Davis Date: 2010-02-19T17:10:40+09:00 Subject: Re: Ruby conditionals subtlety? On Feb 18, 2010, at 23:06 , Albert Schlef wrote: > Farhad Farzaneh wrote: >>> I should also point out: almost all of this is of no consequence. You >>> almost never use defined? on a local variable like this. You usually use >>> it on a const, ivar, cvar, or global, and all of those are unambiguous. >> >> Thanks. I sometimes use it in Rails partials rendering, where I may >> pass an optional local variable, but if it isn't passed, I want to set >> it to some default value. > > BTW, I wonder, > > In templates, local variables are created dynamically (e.g., the > programmer passes a hash of "variables" to the template engine). So how > can Ruby know, in the template code, that a "name" refers to a variable? > By default Ruby thinks names are method invocations and since there's no > assignment, Ruby has no way to know these are variables... that's a rails question. Please take it to a rubyonrails forum (or dig up the code--but I really don't recommend that).