如何找到数组类的长度?

时间:2023-01-31 21:29:53
$param = k.chomp.split("\t")

How can I find the length of $param given that it is an array? actually when I'm writing

如果$param是一个数组,如何找到它的长度?其实当我写作

puts $param.class

I got the o/p like Array. Now how do I find the length of this array?

我有o/p的数组。现在我怎么求这个数组的长度?

I tried $param.length but it's not working.

我试着美元的参数。长度,但不行。

3 个解决方案

#1


33  

Ref Array class

Ref数组类

k = "This \t is \t just \t testing"
$param=k.chomp.split("\t")
array_length= $param.length   #or $param.size
puts "length of $param is : #{array_length}"

o/p

o / p

length of $param is : 4

#2


22  

Try using .size like this:

试着使用。size:

$param.size

#3


2  

Works with:

适用于:

Array.length

or

Array.size

#1


33  

Ref Array class

Ref数组类

k = "This \t is \t just \t testing"
$param=k.chomp.split("\t")
array_length= $param.length   #or $param.size
puts "length of $param is : #{array_length}"

o/p

o / p

length of $param is : 4

#2


22  

Try using .size like this:

试着使用。size:

$param.size

#3


2  

Works with:

适用于:

Array.length

or

Array.size