|
Prev: TO DOWN THE COOL TRISHA!! IMAGES!!!!!!!
Next: Detecting a connection loss && other network questions
From: Roc Ho on 3 Jul 2008 05:30 Hello, Like this: class A attr_accessor :attr1 attr_accessor :attr2 end A.attr1="x" A.attr2="y" Is there any method to code like this : A = {"x", "y"} thanks.
From: Paul Smith on 3 Jul 2008 05:54 class A attr_Accessor :attr1 attr_Accessor :attr2 def initialize(x,y) @attr1=x @attr2=y end end p = A.new("x","y") Or is that not what you meant? On Thu, Jul 3, 2008 at 10:30 AM, Roc Ho <hezepeng(a)huawei.com> wrote: > Hello, > > Like this: > class A > attr_accessor :attr1 > attr_accessor :attr2 > end > > A.attr1="x" > A.attr2="y" > > Is there any method to code like this : > > A = {"x", "y"} > > thanks. > > -- Paul Smith DCI Level 2 Judge, Bath FNM Organiser Upcoming events in Bath - nomadicfun.co.uk July 12th Eventide Prerelease (Standard) paul(a)pollyandpaul.co.uk
From: Heesob Park on 3 Jul 2008 05:55 Hi, 2008/7/3 Roc Ho <hezepeng(a)huawei.com>: > Hello, > > Like this: > class A > attr_accessor :attr1 > attr_accessor :attr2 > end > > A.attr1="x" > A.attr2="y" > > Is there any method to code like this : > > A = {"x", "y"} > > thanks. > > You can use Struct like this: S = Struct.new(:attr1,:attr2) A = S.new('x','y') Or A = Struct.new(:attr1,:attr2).new('x','y') Regards, Park Heesob
From: Roc Ho on 3 Jul 2008 06:11
Thanks Hessob and Paul. ----- Original Message ----- From: "Heesob Park" <phasis(a)gmail.com> To: "ruby-talk ML" <ruby-talk(a)ruby-lang.org> Sent: Thursday, July 03, 2008 5:55 PM Subject: Re: method for assigned value > Hi, > > 2008/7/3 Roc Ho <hezepeng(a)huawei.com>: >> Hello, >> >> Like this: >> class A >> attr_accessor :attr1 >> attr_accessor :attr2 >> end >> >> A.attr1="x" >> A.attr2="y" >> >> Is there any method to code like this : >> >> A = {"x", "y"} >> >> thanks. >> >> > You can use Struct like this: > > S = Struct.new(:attr1,:attr2) > A = S.new('x','y') > > Or > > A = Struct.new(:attr1,:attr2).new('x','y') > > Regards, > > Park Heesob > |