From: "Darryl L. Pierce" Date: 2013-02-27T05:53:00+09:00 Subject: Re: undefined local variable or method `m' --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> # > >> foo.display > NameError: undefined local variable or method `m' for > # > from (irb):7:in `display' > from (irb):11 > from /usr/bin/irb:12:in `
' 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 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--