Hi i hava a database tst with attributes d1 and d2 in an array a=["d1","d2"] to get to the value of tst.d1 i can use tst.send a[0].to_sym how can i change the value of d1 in this way ? something like tst.send a[0].to_sym = "hello" ?? Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
On Tue, 03 Jul 2012 09:20:11 +0200 "Sebastian H." <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> to get to the value of tst.d1 i can use > tst.send a[0].to_sym > > how can i change the value of d1 in this way ? > something like > tst.send a[0].to_sym = "hello" ??Almost, but, you myst to send `:d1=` symbol, so correct call is: tst.send :"#{a[0]}=" = "hello" -- Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov-962d5TIgE1qHXe+LvDLADg@public.gmane.org *Origin: Happy Hacking!
1.9.3-p125 :039 > us.bslnk.send :"#{tst}=" = false SyntaxError: (irb):39: syntax error, unexpected ''='', expecting $end us.bslnk.send :"#{tst}=" = false ^ ------- iwie tut das nicht :( -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
On Tue, 03 Jul 2012 13:37:46 +0200 "Sebastian H." <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 1.9.3-p125 :039 > us.bslnk.send :"#{tst}=" = false > SyntaxError: (irb):39: syntax error, unexpected ''='', expecting $end > us.bslnk.send :"#{tst}=" = false > ^ > ------- > > iwie tut das nicht :( >I don''t speak Deutsch, but I guess I understood you. Sorry it was my mistake (copy-paste is evil): us.bslnk.send :"#{tst}=" false -- Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov-962d5TIgE1qHXe+LvDLADg@public.gmane.org *Origin: Happy Hacking!
On 3 July 2012 13:04, Aleksey V Zapparov <ixti-IGUgQLVVQiRCV4ILt04nZQ@public.gmane.org> wrote:> I don''t speak Deutsch, but I guess I understood you. Sorry it was my > mistake (copy-paste is evil): > > us.bslnk.send :"#{tst}=" falseYou''re probably going to need a comma in there to separate the parameters being passed to .send us.bslnk.send :"#{tst}=", false It may be clearer in this instance to be explicit with parantheses: us.bslnk.send(:"#{tst}=", false) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
On Tue, 3 Jul 2012 14:07:37 +0100 Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 3 July 2012 13:04, Aleksey V Zapparov <ixti-IGUgQLVVQiRCV4ILt04nZQ@public.gmane.org> wrote: > > I don''t speak Deutsch, but I guess I understood you. Sorry it was my > > mistake (copy-paste is evil): > > > > us.bslnk.send :"#{tst}=" false > > You''re probably going to need a comma in there to separate the > parameters being passed to .send > > us.bslnk.send :"#{tst}=", false > > It may be clearer in this instance to be explicit with parantheses: > > us.bslnk.send(:"#{tst}=", false)Yes, sorry - feel kinda messy today. Thanks for fixing me. -- Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov-962d5TIgE1qHXe+LvDLADg@public.gmane.org *Origin: Happy Hacking!
On 3 July 2012 08:20, Sebastian H. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > > i hava a database tst with attributes d1 and d2 > > in an array a=["d1","d2"] > > to get to the value of tst.d1 i can use > > tst.send a[0].to_sym > > how can i change the value of d1 in this way ? > > something like > > tst.send a[0].to_sym = "hello" ??I would be interested to know why you need to do this. In my experience it is very unusual to have a requirement like this, often there is a better way of satisfying the underlying requirement. Colin> > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.