text is method from the Somthingclass that should
work, but I get undefined variable for something.text
Others answered why it’s bad to use eval in this scenario (as it is
is most scenarios where it can be avoided), I’ll answer why the above
doesn’t work: by calling eval inside the each block you’re creating
block-local variables which disappear right after you leave the block
(i.e., on the eval’s closing curly brace).
As for why using eval "@#{x[0]} = …" works – in this example you’re
creating instance variables on the current object, and these live on
after the block ends.
— Shot
···
--
The Ruby community should proceed with all deliberate
speed towards ISO standardization of the language.
thanks, really good, got the code working without eval, nice to know for
future about the blocks! learning more each day , soon I'll be able
to write some decent Ruby code!! thanks again
eval has some security implications and is slow compared to "regular" code Use it only as a last resort for things that cannot be solved otherwise (e.g. generated code).
Cheers
robert
···
On 01.09.2009 02:32, Arthur Rats wrote:
iyo, why wouldnt this be good, not that I know better,but need to learn