I come from the Java world so I was shocked to discover that arrays (http://ruby-doc.org/core/classes/Array.html) does not hava a method contains(object) returning bool.
What is the good way - the Ruby way - of doing that ?
I come from the Java world so I was shocked to discover that arrays (http://ruby-doc.org/core/classes/Array.html) does not hava a method contains(object) returning bool.
What is the good way - the Ruby way - of doing that ?
array.include?(obj) → true or false
Returns true if the given object is present in self (that is, if any object == anObject), false otherwise.
a = [ "a", "b", "c" ]
a.include?("b") #=> true
a.include?("z") #=> false
This, from the Array class documentation:
ruby-1.9.2-p0 > [1,2,3].include? 3
=> true
ruby-1.9.2-p0 > [1,2,3].include? 33
=> false