snow-deprecated icon indicating copy to clipboard operation
snow-deprecated copied to clipboard

Magic constants.

Open Mikoangelo opened this issue 16 years ago • 7 comments
trafficstars

Snow needs a way to dynamically refer to the current file, directory, line, and preferably function name (currently problematic).

I think FILE et al works fine, albeit slightly un-Snowy.

Mikoangelo avatar Jun 27 '09 17:06 Mikoangelo

The FILE should be __FILE__, of course. The iPhone keyboard doesn't have a backtick; sorry about that.

Mikoangelo avatar Jun 27 '09 18:06 Mikoangelo

__FILE__ and __LINE__ are what people know, so why not. Also, they can be implemented directly in the parser with very little effort.

simonask avatar Jun 27 '09 18:06 simonask

Alright, I'm all for it. Up for consideration are also $file/$FILE and $line/$LINE.

Regardless, I think we should preemptively answer people's prayers by making __DIR__ as well. I can't tell you how many times I've heard that plea from foaming hordes of Rubyists, tired of writing File.dirname(__FILE__) all the time.

Mikoangelo avatar Jun 27 '09 19:06 Mikoangelo

I concur.

simonask avatar Jun 28 '09 09:06 simonask

It would also be nice if __FILE__ and __DIR__ was a Pathname (or something similar to Ruby's Pathname) instead of a String, so we could do things like:

require(__DIR__.parent.join('lib', 'lib'))

judofyr avatar Jun 28 '09 10:06 judofyr

I concur with Judofyr. My experience in Ruby is that these are by far used enough to warrant wrapping that string in a more semantic class to ease manipulation.

We need a Pathname class in stdlib, pronto!

Mikoangelo avatar Jun 30 '09 03:06 Mikoangelo

As long as it gets a sensible string conversion, I'm all for it.

simonask avatar Jun 30 '09 06:06 simonask