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
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
Almost, but, you myst to send `:d1=` symbol, so correct call is:
tst.send :"#{a[0]}=" = "hello"
1.9.3-p125 :039 > us.bslnk.send :"#{tst}=" = false SyntaxError: (irb):39: syntax error, unexpected '=', expecting $end us.bslnk.send :"#{tst}=" = false ^
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.
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