當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Vector to_a()用法及代碼示例

to_a()是Ruby中的內置方法,返回帶有vector元素的數組

用法: vec1.to_a()

參數:該函數不接受任何參數


返回值:返回帶有向量元素的數組

例子1

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

輸出

1
2
3

例子2

# Ruby program for to_a() method in Vector 
     
# Include matrix  
require "matrix"   
    
# Initialize the vector 
vec1 = Vector[1, 2, 3, 4, 5] 
    
# Prints the array  
puts vec1.to_a()

輸出

1
2
3
4
5


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Vector to_a() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。