Ruby - Methods
What will be the output of the following Ruby code?
arr = [1, 2, 3] arr.reverse puts arr.inspect arr.reverse! puts arr.inspect
arr = [1, 2, 3] arr.reverse puts arr.inspect arr.reverse! puts arr.inspect
arr.reverse effectarr.reverse returns a new reversed array but does not change arr itself, so arr.inspect prints the original: [1, 2, 3].arr.reverse! effectarr.reverse! reverses arr in place, changing it to [3, 2, 1]. So the second print shows [3, 2, 1].15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions