📜  红宝石 |向量大小()函数

📅  最后修改于: 2022-05-13 01:55:13.639000             🧑  作者: Mango

红宝石 |向量大小()函数

size()是 Ruby 中的内置方法,返回向量中元素的数量

示例 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