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,
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs