--BzCohdixPhurzSK4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Feb 27, 2013 at 02:05:07AM +0900, Love U Ruby wrote:
> >> class Test
> >> m=3Dself
> >> def self.show
> >> print "hi"
> >> end
> >> def display
> >> m.show
> >> end
> >> end
> =3D> nil
>=20
> Why does the below error come? can anyone help me here?
>=20
> >> foo =3D Test.new
> =3D> #<Test:0x0000000106f9b8>
> >> foo.display
> NameError: undefined local variable or method `m' for
> #<Test:0x0000000106f9b8>
>   from (irb):7:in `display'
>   from (irb):11
>   from /usr/bin/irb:12:in `<main>'

Since your variable is m and not @m (instance scope) or @@m (class
scope) then it doesn't exist when the display function is called.

--=20
Darryl L. Pierce <mcpierce / gmail.com>
http://mcpierce.multiply.com/
"What do you care what people think, Mr. Feynman?"

--BzCohdixPhurzSK4
Content-Type: application/pgp-signature

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

iEYEARECAAYFAlEtIKUACgkQtddqM0QFuLLVngCfXAQYC26/4F4Ymw93UkFt/Gbj
nZoAni7g3ZHVI2XhIl37TvN/+Pwq0/cI
=Tvh3
-----END PGP SIGNATURE-----

--BzCohdixPhurzSK4--

On Wed, Feb 27, 2013 at 02:05:07AM +0900, Love U Ruby wrote:
> >> class Test
> >> m=3Dself
> >> def self.show
> >> print "hi"
> >> end
> >> def display
> >> m.show
> >> end
> >> end
> =3D> nil
>=20
> Why does the below error come? can anyone help me here?
>=20
> >> foo =3D Test.new
> =3D> #<Test:0x0000000106f9b8>
> >> foo.display
> NameError: undefined local variable or method `m' for
> #<Test:0x0000000106f9b8>
>   from (irb):7:in `display'
>   from (irb):11
>   from /usr/bin/irb:12:in `<main>'

Since your variable is m and not @m (instance scope) or @@m (class
scope) then it doesn't exist when the display function is called.

--=20
Darryl L. Pierce <mcpierce / gmail.com>
http://mcpierce.multiply.com/
"What do you care what people think, Mr. Feynman?"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (GNU/Linux)

iEYEARECAAYFAlEtIKUACgkQtddqM0QFuLLVngCfXAQYC26/4F4Ymw93UkFt/Gbj
nZoAni7g3ZHVI2XhIl37TvN/+Pwq0/cI
=Tvh3
-----END PGP SIGNATURE-----