if results.length > 0
results
else
raise "No hits!"
end
end
end
Is this what you want?
Semin
Well, not quite. find(:first) is going to be nil or a Shape object.
If it’s nil, you can’t call nil.length and if it’s a Shape object,
then Shape#length might actually be something else.
if results.length > 0
results
else
raise "No hits!"
end
end
end
Is this what you want?
Semin
Well, not quite. find(:first) is going to be nil or a Shape object.
If it’s nil, you can’t call nil.length and if it’s a Shape object,
then Shape#length might actually be something else.
for either case, you might just return the find() and let the caller
check for nil or iterate over the empty array
(Even if find(:all, …) only gets a single match, it will still be in
an array.)
I noodled with something like that but ran into problems with
subsequent steps which got me sidetracked. I now have that sorted
out. I apparenty had my head warped by the combination of what Rails
was doing, Ruby’s implied return, and the class vs instance scoping
of methods and my own arbitrary attributes added to the model.
My son managed to unwarp all that, and now I can see again.
Thx.
– gw
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.