Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Latest commit

 

History

History
28 lines (23 loc) · 625 Bytes

File metadata and controls

28 lines (23 loc) · 625 Bytes

list

We can do the equivalent of PHP's list function in Ruby using parallel assignment. In Ruby we can assign comma separated variables to elements of an array using the normal assignment operator.

{{code:php $attributes = array('Joe', 25, 'blonde'); list($name, $age, $hair) = $attributes; print $name; // => 'Joe' print $age; // => 25 print $hair; // => 'blonde' }}

{{code:ruby attributes = ["Joe", 25, "blonde"] name, age, hair = attributes puts name # => "Joe" puts age # => 25 puts hair # => "blonde" }}

{{related: array/each array/array array/extract }}