--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 Gabriel y Gal 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:
> >
> > odule Kernel
> > ef executed?
> > _FILE__ == $0
> > nd
> > nd
> >
> > f executed?
> > uts 'awesomesauce'
> > lse
> > uts 'failsauce'
> > nd
> >
> > What am I missing in the constraints of the request?
> 
> 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.

> 
> A solution, which I don't know if it feels clean enough would be to
> pass that to the method:
> 
> #executed.rb
> module Kernel
>   def executed? file=__FILE__
>     file == $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?)

-- 
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
7w
-----END PGP SIGNATURE-----

--Nq2Wo0NMKNjxTN9z--