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?)
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?)
Dominic S. 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?)
Uh… Wouldn’t a hash of hashes do the trick?
For example,
my_hash[:key][:price] = 1.99
my_hash[:key][:quantity] = 5
…
or
my_hash[:key] = { :price => 1.99, :quantity => 5 }
or whatever the syntax is.
Yes, i was thinking your later suggestion, but how do i iterate through
them…
the price, and quanity come back too containated (ie : 1.995 ) do i have
to mess with a .split and reg exp at this point? please say it isn’t so!
Robert H. wrote:
Dominic S. 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?)
Uh… Wouldn’t a hash of hashes do the trick?
For example,
my_hash[:key][:price] = 1.99
my_hash[:key][:quantity] = 5
…or
my_hash[:key] = { :price => 1.99, :quantity => 5 }
or whatever the syntax is.
Dominic S. 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?)
–
Posted via http://www.ruby-forum.com/.
Just add the items as an array or another container object.
On 12.10.2006 20:22, Dominic S. 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’
=> trueEntry = Struct.new(:price, :quantity, :name)
=> Entryh = Hash.new {|h,k| h[k] = Entry.new}
=> {}h[:foo].price = 10
=> 10h[:bar].name = “bar”
=> “bar”h[:foo].name = “foo”
=> “foo”pp h
{:bar=>#,
:foo=>#}
=> nil
robert
Robert K. wrote:
On 12.10.2006 20:22, Dominic S. 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?
PS: Alternatively you can use OpenStruct.
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs