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
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..
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 {
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 = ''
>>
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'
5 matches
Mail list logo