What is the use of destructive method?

Questions by RyanJames   answers by RyanJames

Showing Answers 1 - 3 of 3 Answers

It is a method that alters the attribute of an object.

myabcs = ['a', 'b', 'c']
#myabcs is of type Array.

myabcs.reverse!
# this method altered the object.

p myabcs

#outputs:
#["c", "b", "a"]

For this to work the method must return a reference of itself and not a fixed value

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions