Open In App

Ruby | Vector elements() function

Improve
Improve
Like Article
Like
Save
Share
Report

The elements() is an inbuilt method in Ruby returns the vector which is created using the array

Syntax: Vector.elements(array)

Parameters: The function accepts a parameter array

Return Value: It returns the vector which is created using the array.

Example 1:




#Ruby program for elements() method in Vector
  
#Include matrix
require "matrix"
  
#Initialize the array
    arr
    = [ 1, 2, 3 ]
  
#Initialize the vector
    vec1
    = Vector.elements(arr)
  
#prints the new vector
          puts vec1


Output:

Vector[1, 2, 3]

Example 2:




#Ruby program for elements() method in Vector
  
#Include matrix
require "matrix"
  
#Initialize the vector
    vec1
    = Vector.elements([ 1, 2, 3 ])
  
#prints the new vector
          puts vec1


Output:

Vector[1, 2, 3]

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads