Ruby include? array method
In ruby programming language include? method, are used to check particular object in array. Such as object is present in array or not. Syntax of this method as follows.
Syntax | Array.include?() |
Parameter | Object |
Return | (true,false) |
Ruby include? method example
This method are compared inner element of array to given objects. When object is same type and its value are similar then this returns a true value otherwise return false. Let see an example.
# Example Array.include?
# Test array
record = [1,"code",2,[10,20],6,4,15]
# Test include
a = record.include?(6)
b = record.include?(7)
c = record.include?([10,20])
# Display array
print(" record ",record)
# Display result
print("\n is include? 6 : ", a)
print("\n is include? 7 : ", b)
print("\n is include? [10,20] : ", c)

record [1, "code", 2, [10, 20], 6, 4, 15]
is include? 6 : true
is include? 7 : false
is include? [10,20] : true
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment