Variable symbol

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

On Tue, 03 Jul 2012 09:20:11 +0200
“Sebastian H.” [email protected] 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: [email protected]

*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
^

it doesn’t work :frowning:

On Tue, 03 Jul 2012 13:37:46 +0200
“Sebastian H.” [email protected] 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 :frowning:

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: [email protected]

*Origin: Happy Hacking!

On 3 July 2012 13:04, Aleksey V Zapparov [email protected] 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)

On Tue, 3 Jul 2012 14:07:37 +0100
Michael P. [email protected] wrote:

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: [email protected]

*Origin: Happy Hacking!

On 3 July 2012 08:20, Sebastian H. [email protected] wrote:

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