Ruby/Array/include
Материал из Wiki.crossplatform.ru
Check an Array for a Certain Item
# The include? method returns true if the supplied parameter is in the array, # and false otherwise: x = [1, 2, 3] puts x.include?("x") puts x.include?(3)
include? with parenthesis
year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009] year.include?( 2010 ) # => false
Is an element in this array
year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009] puts year.include? 2004 # => true