From: Chad Perrin Date: 2011-06-03T01:34:27+09:00 Subject: Re: CORE - Replace "if __FILE__ == $0" with "executed?" --XF85m9dhOBO43t/C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 02, 2011 at 10:51:46PM +0900, Peter Zotov wrote: >=20 > It failed because __FILE__ is not a constant: it is a special lexical > construct which is replaced by just a string containing the filename at > the point of _loading_ the file, i.e. even before the execution begins. > You simply cannot access it in any way after the file was loaded. >=20 > You can still implement it this way (note that it may not work on=20 > implementations other > than MRI): [snip] This seems to work just fine: module Kernel def executed? __FILE__ =3D=3D $0 end end if executed? puts 'awesomesauce' else puts 'failsauce' end What am I missing in the constraints of the request? --=20 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] --XF85m9dhOBO43t/C Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAk3nuCcACgkQ9mn/Pj01uKWlnQCfRsJARY/9muhK+GY7Tl8ARRLM hGEAoL5ZjOpjZMOW0VzALR/1BqDtJuBQ =pgTy -----END PGP SIGNATURE----- --XF85m9dhOBO43t/C--