Syntax Below example will show how to define and print array values. Example # array declaration arr = Array.[](1,"Java","FLutter",1.2) # printing array elements puts "Elements of \'arr\' are:" puts arr # empty array declaration arr1 = Array.[]() puts "Number of elements present in \'arr1\' are: #{arr1.count}" Output How to create array from User input? Below example will show it Example 2 # input array elements puts "Enter the first element " ele1 = gets.chomp puts "Enter the second element " ele2 = gets.chomp puts "Enter the third element " ele3 = gets.chomp puts "Enter the fourth element " ele4 = gets.chomp # creating array using input elements arr = Array.[](ele1,ele2,ele3,ele4) # printing array elements puts "Array elements are:" puts arr Output
array_name = Array.[]('ele1', 'ele2' , ... ,'eleN')
Elements of 'arr' are:
1
Java
FLutter
1.2
Number of elements present in 'arr1' are: 0
Enter the first element
1
Enter the second element
'chandu'
Enter the third element
'flutter'
Enter the fourth element
1.2
Array elements are:
1
'chandu'
'flutter'
1.2
Program to Print Triangle of Numbers in Ruby
how to create an array with Array.[](*args) in Ruby ?
Ruby program to check whether the given number is prime or not
How to create two dimensional array in ruby?
Ruby program to print an array
How to Get Input with Gets in Ruby
How to add/remove elements to Array in Ruby?
What are some of your favorite gems? What are their alternatives?
What are the various Ruby runtimes, and how are they different?
How to Replace array elements in Ruby?
Ruby program to check whether the given number is Armstrong
What's the difference between a lambda, a block and a proc?
Ruby program to print Fibonacci series
Ruby program to check whether the given number is palindrome
What are #method_missing and #send? Why are they useful?
Ruby program to add two integer numbers
Ruby program to generate random numbers
Ruby program to Calculate the factorial of given number
How to Sort Array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
How to shuffle an array in Ruby?
Ruby program to reverse a string
How to get index of array element in Ruby