Check if an array/hash contains a particular element

Hi,

Is there any convenient method to check if an array contains a
particular element? eg.

abc = {‘ele1’,‘ele2’}

if abc contains ‘ele1’
========
blablablab…
end

Thanks.

Hi –

On Thu, 28 Sep 2006, Ianne L. wrote:

Hi,

Is there any convenient method to check if an array contains a
particular element? eg.

abc = {‘ele1’,‘ele2’}

That’s a hash, not an array. I think you mean:

[“ele1”, “ele2”]

if abc contains ‘ele1’

if abc.include?(‘ele1’)

David


David A. Black | [email protected]
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

Is there any convenient method to check if an array contains a
particular element? eg.

abc = {‘ele1’,‘ele2’}

abc.include? ‘ele1’

Steve