Forum: Ruby Re: Creating Hash of Arrays

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berger, Daniel (Guest)
on 2006-05-23 00:42
(Received via mailing list)
>
> 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.
This topic is locked and can not be replied to.