Ruby | Vector elements() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like 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: CPP #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: CPP #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] Comment More infoAdvertise with us Next Article Ruby | Vector elements() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Vector-class Similar Reads Ruby | Vector eql?() function The eql?() is an inbuilt method in Ruby returns boolean value true if two vectors are same otherwise false Syntax: vec1.eql?(vec2) Parameters: The function accepts a single vector as parameters Return Value: It returns boolean value true if two vectors are same otherwise false Example 1: Ruby # Ruby 1 min read Ruby | Vector component() function The component() is an inbuilt method in Ruby returns element at index i in the vector. Indexing starts from zero. Syntax: vec1.component(i) Parameters: The function accepts a single parameter Return Value: It returns element at index i in the vector Example 1: CPP #Ruby program for component() metho 1 min read Ruby | Vector covector() function The covector() is an inbuilt method in Ruby returns a single-row matrix created using vector Syntax: vec1.covector() Parameters: The function accepts no parameter Return Value: It returns a single-row matrix created using vector Example 1: CPP #Ruby program for covector() method in Vector #Include m 1 min read Ruby | Vector to_a() function The to_a() is an inbuilt method in Ruby returns the array with elements of vector Syntax: vec1.to_a() Parameters: The function accepts no parameter Return Value: It returns the array with elements of vector Example 1: Ruby # Ruby program for to_a() method in Vector # Include matrix require "mat 1 min read Ruby | Vector r() function The r() is an inbuilt method in Ruby returns the Pythagorean distance of the vector. Syntax: vec1.r() Parameters: The function accepts no parameter Return Value: It Pythagorean distance of the vector Example 1: Ruby # Ruby program for r() method in Vector # Include matrix require "matrix" 1 min read Like