Robert Klemme
10/13/2006 9:10:00 AM
On 12.10.2006 20:22, Dominic Son wrote:
> Hi. There's got to be an easy way to do this.
>
> I simply want multiple iteams (etc, price, quantity, and name) appended
> to a key..
>
> There's got to be a simple way (...right?)
Like this?
>> 11:09:28 [~]: irbs
>> require 'pp'
=> true
>> Entry = Struct.new(:price, :quantity, :name)
=> Entry
>> h = Hash.new {|h,k| h[k] = Entry.new}
=> {}
>> h[:foo].price = 10
=> 10
>> h[:bar].name = "bar"
=> "bar"
>> h[:foo].name = "foo"
=> "foo"
>> pp h
{:bar=>#<struct Entry price=nil, quantity=nil, name="bar">,
:foo=>#<struct Entry price=10, quantity=nil, name="foo">}
=> nil
robert