DEV Community

Cover image for Ruby Instance Methods
Bin
Bin

Posted on

Ruby Instance Methods

Introduction

Below is some instances method in Ruby might help you easily solving the issue.

.flatten()

.flatten() is method will return a new array that flattening of itself and it also taking argument to determine the level of recursion to flatten.

Alt Text

.reverse()

.reverse() method will return a new array containing self's elements in reverse order.

Alt Text

.rotate()

.rotate() method will rotate first element of self and return by new array and it also taking argument to determine how many element need to rotate, if passing negative argument like (-1) then it will rotate in opposite direction

Alt Text

.insert()

.insert() method is taking at least two argument, first argument is index of array, and second argument is value that you are going to insert, if using negative index will insert the value at the end of array

Alt Text

References:
API DOCK

Top comments (0)