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.
精彩评论