开发者

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

In PHP there is code like this:

<?php
 开发者_如何学JAVA$myarray [] = "Hello";
 $myarray [] = "BOB";
for($i = 0; $i < count($myarray); $i++) echo $myarray[$i];
?>

Is there any code like this in Ruby-On-Rails?


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


Arrays already automatically grow, nothing special needed. The Ruby equivalent would be:

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

This will print out "Hello" and "BOB" on their own lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜