__dir__ won't work with embed paths such as uri:classloader: (#4611) #4658
as adviced in #4611 (comment)
... this is relying on the existing uri:classloader: handling logic in
verified this works fine for liquid gem's case presented in #4611
still need to figure out a where to put a test-case to test this properly
The caller logic needs to be there because jitted methods don't set context.getFile to anything. This is obviously unfortunate since it requires generating a stack trace and then mining the filename out of it.
A future improvement would be to mark "file" as a frame field needed for code that calls anything like "dir". It would force a frame and force setting file so that downstream calls could pick it up.
Another would be to implement dir as a pseudo-keyword, not making a call if we know it's the builtin one, so it can access the filename of the current method directly. dir would essentially compile down to
PR looks good to me!
... if getAbsolutePath is used - which seems like its not necessary and we can pretty much just do what MRI does File.dirname(__FILE__)