Alle 20:52, venerdì 8 dicembre 2006, Chad Thatcher ha scritto:
> Hi, I am new to Ruby and still finding it very strange even though I am
> enjoying learning it immensely.
>
> I have this code:
>
> if an_array.assoc(tag_name) == nil
>  ...
>
> and of course it doesn't work because I either get an array back or a
> nil object.  It makes it very difficult to have a simple if statement
> like the above that can handle both eventualities.  I don't need the
> array returned, I just need to check to see if the element exists to
> take a certain action.
>
>
> What is the Ruby way of doing this?
>
> Thanks,
>
> Chad.

In ruby everything evaluates to true in conditionals, except false and nil. 
So, you can do something like

if an_array.assoc(tag_name) #the element has been found
...
else #in this case assoc returned nil because no element was found
...
end

I hope this answeres your question.

Stefano