Bird
0
0

What does the include? method do when called on an array in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Arrays
What does the include? method do when called on an array in Ruby?
AReturns the number of elements in the array
BChecks if the array contains a specific element
CFlattens nested arrays into a single array
DRemoves duplicate elements from the array
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of include?

    The include? method checks if a given element exists inside the array.
  2. Step 2: Compare with other methods

    length returns count, flatten merges nested arrays, and removing duplicates is done by uniq.
  3. Final Answer:

    Checks if the array contains a specific element -> Option B
  4. Quick Check:

    include? = Check element presence [OK]
Quick Trick: Use include? to test if an element exists in an array [OK]
Common Mistakes:
MISTAKES
  • Confusing include? with length method
  • Thinking include? flattens arrays
  • Assuming include? removes duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes