list
-
We can do the equivalent of PHP’s
listfunction in Ruby using parallel assignment. In Ruby we can assign comma separated variables to elements of an array using the normal assignment operator.PHP
$attributes = array('Joe', 25, 'blonde'); list($name, $age, $hair) = $attributes; print $name; // => 'Joe' print $age; // => 25 print $hair; // => 'blonde'
Ruby
attributes = ["Joe", 25, "blonde"] name, age, hair = attributes puts name # => "Joe" puts age # => 25 puts hair # => "blonde"
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

