From: Christopher Dicely Date: 2008-02-17T07:24:49+09:00 Subject: Re: where to check for nils or empty? Maybe something like this? class Whatever def initialize ... @reviews = [:firstReview, :secondReview, ...] end def process array @reviews.inject(array) do |arr, review| break if arr.nil? || arr.empty? send(review, arr) end end def firstReview array array.reject! {|a| @MasterList.include? (a)} end end On Feb 16, 2008 10:32 AM, John Honovich wrote: > I am processing arrays of URLs. I call a series of methods to delete or > modify those urls. I have a risk that those methods will return an empty > or null array. > > I am trying to figure out where and how to best check if the array is > null or empty. > > > Right now, I am doing it like this: > > def process array > array = firstReview array > return if array.nil? || array.empty? > array = secondReview array > return if array.nil? || array.empty? > # repeat again and again > end > > def firstReview array > array.reject! {|a| @MasterList.include? (a)} > end > > > My approach works currently but feels ugly and repetitive. > > Any advice for improving this? > > Thanks, > > John > -- > Posted via http://www.ruby-forum.com/. > >