--fdj2RfSjLxBAspz7
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Arthur Rats:

> fields =3D [["somthing"]]

> fields.each{|x|
>   eval "#{x[0]} =3D Someclass::Somemethod.new"
> }

> puts something.text=3D"asdfasdfasdf"

> text is method from the Somthingclass that should
> work, but I get undefined variable for something.text

Others answered why it=E2=80=99s bad to use eval in this scenario (as it is
is most scenarios where it can be avoided), I=E2=80=99ll answer why the abo=
ve
doesn=E2=80=99t work: by calling eval inside the each block you=E2=80=99re =
creating
block-local variables which disappear right after you leave the block
(i.e., on the eval=E2=80=99s closing curly brace).

As for why using eval "@#{x[0]} =3D =E2=80=A6" works =E2=80=93 in this exam=
ple you=E2=80=99re
creating instance variables on the current object, and these live on
after the block ends.

=E2=80=94 Shot
--=20
>> The Ruby community should proceed with all deliberate
>> speed towards ISO standardization of the language.
> Yeah, look what it did to Forth.
Don=E2=80=99t just say it, show it. http://vividpicture.com/aleks/atari/for=
th.jpg
        [M. Edward (Ed) Borasky, Matt Lawrence, Gregory Brown, ruby-talk]

--fdj2RfSjLxBAspz7
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkqc+MIACgkQi/mCfdEo8Uq/lgCgs7arT9NaLViTd5KAZRMBe8mn
FloAoJ/OAHUAar1zlnOH1qnitjqz8+dy
=3fVt
-----END PGP SIGNATURE-----

--fdj2RfSjLxBAspz7--

Arthur Rats:

> fields = [["somthing"]]

> fields.each{|x|
>   eval "#{x[0]} = Someclass::Somemethod.new"
> }

> puts something.text="asdfasdfasdf"

> text is method from the Somthingclass that should
> work, but I get undefined variable for something.text

Others answered why its bad to use eval in this scenario (as it is
is most scenarios where it can be avoided), Ill answer why the above
doesnt work: by calling eval inside the each block youre creating
block-local variables which disappear right after you leave the block
(i.e., on the evals closing curly brace).

As for why using eval "@#{x[0]} = " works  in this example youre
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.
> Yeah, look what it did to Forth.
Dont just say it, show it. http://vividpicture.com/aleks/atari/forth.jpg
        [M. Edward (Ed) Borasky, Matt Lawrence, Gregory Brown, ruby-talk]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkqc+MIACgkQi/mCfdEo8Uq/lgCgs7arT9NaLViTd5KAZRMBe8mn
FloAoJ/OAHUAar1zlnOH1qnitjqz8+dy
=3fVt
-----END PGP SIGNATURE-----