有没有一种方法可以让数组像PHP一样自动增长


Is there a way to have an array that automatically grows like in PHP?

在PHP中有这样的代码:

<?php
 $myarray [] = "Hello";
 $myarray [] = "BOB";
for($i = 0; $i < count($myarray); $i++) echo $myarray[$i];
?>

在Ruby-On-Rails中有这样的代码吗?

strings << "Hello" << "BOB"
strings.each { |string| print string }

数组已经自动增长了,没有什么特别需要的。Ruby的等效代码是:

list = []
list.push("Hello", "BOB")
list.each {|row| puts row}

这将在各自的行上打印出"Hello"answers"BOB"