# Re: Creating Hash of Arrays

**URL:** <https://www.ruby-forum.com/t/re-creating-hash-of-arrays/95140>\
**Category:** Ruby\
**Created:** [May 22, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/re-creating-hash-of-arrays/95140 "2006-05-22T22:42:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 22, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/re-creating-hash-of-arrays/95140/1 "2006-05-22T22:42:27Z")

</div>

> ## Pseudo Code
> 
> myhash[‘customercode’][0]=Firstname  
> myhash[‘customercode’][1]=M.I myhash[‘customercode’][2]=Lastname
> 
> myhash.each do |k,v|  
> myhash[‘k’].each do |elm|  
> puts “#{k} -\> elm”  
> end  
> end

Except for a line break or semicolon between the 2nd and 3rd assignment,  
I think your pseudo code will work. Did you try it? irb is your  
friend, btw. 🙂

However, this is Ruby not Perl. There’s no need to use deeply nested  
hash structures when you want an object in Ruby.

class CustomerCode  
attr\_accessor :first\_name, :mi, :lastname  
end

array\_of\_customers.each do |cust|  
cust.first\_name = some\_first\_name  
cust.mi = some\_mi  
cust.last\_name = some\_last\_name  
p cust  
end

Regards,

Dan

This communication is the property of Qwest and may contain confidential  
or  
privileged information. Unauthorized use of this communication is  
strictly  
prohibited and may be unlawful. If you have received this communication  
in error, please immediately notify the sender by reply e-mail and  
destroy  
all copies of the communication and any attachments.
