shuffle!() is a Array class method which shuffles elements in an array Syntax Array.shuffle!() Example: With shuffle!() method we will shuffle the given array elements. a = [1, 22, 123, nil, 2, 3] # declaring array b = [12, 24, 41, 1, 48, 99] # declaring array c = [18, 22, 50, 6] # shuffle! method example puts "shuffle!() method form : #{a.shuffle!()}\n\n" puts "shuffle!() method form : #{b.shuffle!()}\n\n" puts "shuffle!() method form : #{c.shuffle!()}\n\n" Output
shuffle!() method form : [2, 1, 123, 3, nil, 22]
shuffle!() method form : [24, 99, 48, 1, 12, 41]
shuffle!() method form : [50, 18, 6, 22]
How to Replace array elements in Ruby?
How to get index of array element in Ruby
Ruby program to generate random numbers
What are the various Ruby runtimes, and how are they different?
Program to Print Triangle of Numbers in Ruby
Creating Array with Array.new(size, obj) in Ruby
What are #method_missing and #send? Why are they useful?
Ruby program to print an array
Ruby program to add two integer numbers
How to Sort Array in Ruby?
how to create an array with Array.[](*args) in Ruby ?
Ruby program to check whether the given number is palindrome
Ruby program to check whether the given number is prime or not
How to create two dimensional array in ruby?
How to Get Input with Gets in Ruby
What are some of your favorite gems? What are their alternatives?
Ruby program to Calculate the factorial of given number
Ruby program to check whether the given number is Armstrong
Ruby program to reverse a string
How to add/remove elements to Array in Ruby?
What's the difference between a lambda, a block and a proc?
Ruby program to print Fibonacci series
How to shuffle an array in Ruby?