红宝石 |向量大小()函数
size()是 Ruby 中的内置方法,返回向量中元素的数量
Syntax: vec1.size()
Parameters: The function accepts no parameter
Return Value: It returns the number of elements in the vector
示例 1 :
# Ruby program for size() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 2, 3]
# Prints the size of vector
puts vec1.size()
输出:
3
示例 2 :
# Ruby program for size() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 2, 3, 4, 5]
# Prints the size of vector
puts vec1.size()
输出:
5