--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jun 03, 2011 at 01:51:59AM +0900, Jes=FAs Gabriel y Gal=E1n wrote:
> On Thu, Jun 2, 2011 at 6:34 PM, Chad Perrin <code / apotheon.net> wrote:
> > On Thu, Jun 02, 2011 at 10:51:46PM +0900, Peter Zotov wrote:
> >>
> >> 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.
> >>
> >> You can still implement it this way (note that it may not work on
> >> implementations other
> >> than MRI):
> >
> > [snip]
> >
> > This seems to work just fine:
> >
> > =A0 =A0module Kernel
> > =A0 =A0 =A0def executed?
> > =A0 =A0 =A0 =A0__FILE__ =3D=3D $0
> > =A0 =A0 =A0end
> > =A0 =A0end
> >
> > =A0 =A0if executed?
> > =A0 =A0 =A0puts 'awesomesauce'
> > =A0 =A0else
> > =A0 =A0 =A0puts 'failsauce'
> > =A0 =A0end
> >
> > What am I missing in the constraints of the request?
>=20
> He wants to have the definition of the executed? method in a different
> file, which gets required in his main file,

Ah, yeah, I apparently overlooked that.  Please excuse my noise.

>=20
> A solution, which I don't know if it feels clean enough would be to
> pass that to the method:
>=20
> #executed.rb
> module Kernel
>   def executed? file=3D__FILE__
>     file =3D=3D $0
>   end
> end

That's pretty clever.  I like it.  I don't think you'd even need to
explicitly pass the value of __FILE__ there.  (Would you?)

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

--Nq2Wo0NMKNjxTN9z
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk3nzZoACgkQ9mn/Pj01uKXx3wCgwL0fPb1cmRoYW/cu159iyiwm
J08AoPQqkJm8ec53RHt9yTDSvOupogcD
=Sf7w
-----END PGP SIGNATURE-----

--Nq2Wo0NMKNjxTN9z--

On Fri, Jun 03, 2011 at 01:51:59AM +0900, Jes=FAs Gabriel y Gal=E1n wrote:
> On Thu, Jun 2, 2011 at 6:34 PM, Chad Perrin <code / apotheon.net> wrote:
> > On Thu, Jun 02, 2011 at 10:51:46PM +0900, Peter Zotov wrote:
> >>
> >> 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.
> >>
> >> You can still implement it this way (note that it may not work on
> >> implementations other
> >> than MRI):
> >
> > [snip]
> >
> > This seems to work just fine:
> >
> > =A0 =A0module Kernel
> > =A0 =A0 =A0def executed?
> > =A0 =A0 =A0 =A0__FILE__ =3D=3D $0
> > =A0 =A0 =A0end
> > =A0 =A0end
> >
> > =A0 =A0if executed?
> > =A0 =A0 =A0puts 'awesomesauce'
> > =A0 =A0else
> > =A0 =A0 =A0puts 'failsauce'
> > =A0 =A0end
> >
> > What am I missing in the constraints of the request?
>=20
> He wants to have the definition of the executed? method in a different
> file, which gets required in his main file,

Ah, yeah, I apparently overlooked that.  Please excuse my noise.

>=20
> A solution, which I don't know if it feels clean enough would be to
> pass that to the method:
>=20
> #executed.rb
> module Kernel
>   def executed? file=3D__FILE__
>     file =3D=3D $0
>   end
> end

That's pretty clever.  I like it.  I don't think you'd even need to
explicitly pass the value of __FILE__ there.  (Would you?)

--=20
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk3nzZoACgkQ9mn/Pj01uKXx3wCgwL0fPb1cmRoYW/cu159iyiwm
J08AoPQqkJm8ec53RHt9yTDSvOupogcD
=Sf7w
-----END PGP SIGNATURE-----