[Ruby] Active Record and Array error

Laurel Fan laurel.fan at gmail.com
Thu Jun 21 12:20:11 PDT 2007


On 6/21/07, Neil Moomey <neil at motznik.com> wrote:
>   def owners
>     owner_array=[]
>     owner_array << "Owner1="+self.Owner1 unless self.Owner1.nil? ||
> self.Owner1.strip == ""
>     owner_array << "Owner2="+self.Owner2 unless self.Owner2.nil? ||
> self.Owner2.strip == ""
>     owner_array << "Owner3="+self.Owner3 unless self.Owner3.nil? ||
> self.Owner3.strip == ""
>   end

The last line of this method is returning nil when Owner3 is nil.  I'm
not sure what that code is trying to do, but try throwing some more
parentheses in it, or an old-fashioned "return owner_array". Also
check out Array.map/collect (map and collect are aliases) and
array.compact, they might do what you want already.

-- 
Laurel Fan
http://blog.gorgorg.org


More information about the Ruby mailing list