for example:
[ (id=>1, email=>'[email protected]', name=>'tim'),
(id=>2, email=>'[email protected]', name=>'joe'),
(id=>3, email=>'[email protected]', name=>'dan') ]
How can I extract the email column and put it in its own array?
for example:
[ (id=>1, email=>'[email protected]', name=>'tim'),
(id=>2, email=>'[email protected]', name=>'joe'),
(id=>3, email=>'[email protected]', name=>'dan') ]
How can I extract the email column and put it in its own array?
Let's call your array users
. You can do this:
users.map{|u| u[:email]}
This looks at the hashes one by one, calling them u
, extracts the :email
key, and returns the results in a new array of user emails.
[ {id=>1, email=>'[email protected]', name=>'tim'},
{id=>2, email=>'[email protected]', name=>'joe'},
{id=>3, email=>'[email protected]', name=>'dan'} ].map{|h| h['email']}