[Rails] Re: Simple ruby syntax: variable assignment

2011-04-23 Thread Matt Jones
On Apr 22, 12:32 pm, David Kahn wrote: > Just curious if there is a more elegant way to set a variable if it happens > to not exist yet. I often find I am doing somthing like the following: > >     regex = '' >     10.times { regex += '.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*\n' } > A mostly u

Re: [Rails] Re: Simple ruby syntax: variable assignment

2011-04-22 Thread David Kahn
On Fri, Apr 22, 2011 at 1:42 PM, Jazmin wrote: > I guess you could do something like this: > x = defined?(x) ? x+="string" : "" Thanks Jazmin, this is the kind of thing I was looking for although I guess in the end it is probably less readable than just assigning the variable at the top, hmmm..

Re: [Rails] Re: Simple ruby syntax: variable assignment

2011-04-22 Thread Jazmin
I guess you could do something like this: x = defined?(x) ? x+="string" : "" You can assign a value to a variable if it doesn't exist like this: s ||= "" but in your case you want to use the operand + so the string needs to exist. Also an alternative for the loop example regex = '' 10.times {

Re: [Rails] Re: Simple ruby syntax: variable assignment

2011-04-22 Thread David Kahn
On Fri, Apr 22, 2011 at 1:15 PM, Kendall Gifford wrote: > On Friday, April 22, 2011 10:32:35 AM UTC-6, DK wrote: >> >> Just curious if there is a more elegant way to set a variable if it >> happens to not exist yet. I often find I am doing somthing like the >> following: >> >> regex = '' >>

[Rails] Re: Simple ruby syntax: variable assignment

2011-04-22 Thread Kendall Gifford
On Friday, April 22, 2011 10:32:35 AM UTC-6, DK wrote: > > Just curious if there is a more elegant way to set a variable if it happens > to not exist yet. I often find I am doing somthing like the following: > > regex = '' > 10.times { regex += '.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*\n'