Ruby | Vector zero() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The zero() is an inbuilt method in Ruby returns the vector of size N with elements equals to 0. Syntax: Vector.zero(N) Parameters: The function accepts a parameter which represents the size of the array. Return Value: It returns the vector of size N with elements equals to 0. Example 1: Ruby #Ruby program for zero method in Vector #Include matrix require "matrix" #Initialize the vector vec1 = Vector.zero(4) #prints the new vector puts vec1 Output: Vector[0, 0, 0, 0] Example 2: Ruby #Ruby program for zero method in Vector #Include matrix require "matrix" #Initialize the vector vec1 = Vector.zero(3) #prints the new vector puts vec1 Output: Vector[0, 0, 0] Comment More infoAdvertise with us Next Article Ruby | Vector zero?() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Vector-class Similar Reads Ruby | Vector zero?() function The zero?() is an inbuilt method in Ruby returns boolean value true if all elements of vector are equals to zero otherwise false Syntax: vec1.zero?() Parameters: The function accepts no parameter Return Value: It returns boolean value true if all elements of vector are equals to zero otherwise false 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 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 hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 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 norm() function The norm() is an inbuilt method in Ruby returns the pythagorean distance of the vector. Syntax: vec1.norm() Parameters: The function accepts no parameter Return Value: It pythagorean distance of the vector Example 1: Ruby # Ruby program for norm() method in Vector # Include matrix require "matr 1 min read Like