Multiple choice technology programming languages

“name” is an array.Which of the following are correct way to find size of a ruby array? Select all that apply.

  1. name.length

  2. name.size

  3. size(name)

  4. length(name)

Reveal answer Fill a bubble to check yourself
A,B Correct answer
Explanation

In Ruby, both length and size are valid methods to get the number of elements in an array. They are aliases and return the same result. Options C and D are incorrect because size(name) and length(name) are not valid Ruby syntax - these methods must be called on the array object itself, not with the array as an argument.