when I’m parsing a csv file, and don’t want to use those elements that
return a nil value, what is the easiest way to do so? I’ve tried:
if record == nil
next
else
where record is the current element from the file.
when I’m parsing a csv file, and don’t want to use those elements that
return a nil value, what is the easiest way to do so? I’ve tried:
if record == nil
next
else
where record is the current element from the file.
On Mar 6, 6:24 pm, Max R. [email protected] wrote:
when I’m parsing a csv file, and don’t want to use those elements that
return a nil value, what is the easiest way to do so? I’ve tried:if record == nil next else
If tend to like boolean expressions rather than comparison with
‘nil’ (or false):
next if record.nil?
or
next unless record
The latter will skip when next is either ‘nil’ or ‘false’.
If you have multiple fields and want to skip if they all are nil/
false:
next unless first or second or third
If you want to skip if any of them are nil/false:
next unless first and second and third
Lars
On Thu, Mar 6, 2008 at 11:24 AM, Max R. [email protected]
wrote:
when I’m parsing a csv file, and don’t want to use those elements that
return a nil value, what is the easiest way to do so? I’ve tried:if record == nil next else
where record is the current element from the file.
Depending on what you are doing, you can parse first, use #compact
after.
Todd
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs