From: Paul Smith Date: 2009-10-23T01:07:21+09:00 Subject: Re: convert/replace a value of nil with 0? 2009/10/22 Jesús Gabriel y Galán : > On Thu, Oct 22, 2009 at 5:24 PM, Mmcolli00 Mom wrote: >> Do you know how I can convert or replace any value that gets back a >> 'nil' to 0? >> >> For instance, the myArrayVal[0] may or may not contain a number and I >> want the code to default to 0 if a nil is returned. I have not found any >> documentation on this. > > irb(main):001:0> array = [] > => [] > irb(main):002:0> value = array[0] || 0 > => 0 > irb(main):003:0> value > => 0 > > Hope this helps, Though that will of course convert false too. > > Jesus. > > -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk