Peña, Botp
7/24/2007 2:18:00 AM
From: Ari Brown [mailto:ari@aribrown.com]
# yes, I mean spontaneously generated variables.
you don't like Struct
irb(main):006:0> v = Struct.new(:yea, :cool, :awesome, :stuff)
=> #<Class:0xb7dd9048>
irb(main):007:0> v1 = v.new("yeah","cool","awesome","stuff")
=> #<struct #<Class:0xb7dd9048> yea="yeah", cool="cool", awesome="awesome", stuff="stuff">
irb(main):008:0> v1.yea
=> "yeah"
irb(main):009:0> v1.yea = "heheh"
=> "heheh"
irb(main):010:0> v1.yea
=> "heheh"
irb(main):011:0> v2 = v.new("yeah","cool","awesome","stuff")
=> #<struct #<Class:0xb7dd9048> yea="yeah", cool="cool", awesome="awesome", stuff="stuff">
irb(main):012:0> v2.yea
=> "yeah"
you can play w your var groups ...
irb(main):014:0> v3 = v1
=> #<struct #<Class:0xb7dd9048> yea="heheh", cool="cool", awesome="awesome", stuff="stuff">
irb(main):015:0> v3.yea
=> "heheh"
but i wish Struct vars or basically ruby's accessors can be initialized, like
v = Struct.new(:yea = "yeah!", :cool = "cool", :awesome = "!", :stuff = ":)" )
less repitition ie.
kind regards -botp