G
Giles Bowkett
There was a thread here recently about this idiom in Rails:
eval(IO.read(file), binding, file)
I changed it to a method:
def eval_file_with_binding(file)
eval(IO.read(file), binding, file)
end
It appeared twice in Rails, so refactoring it was kind of overkill,
but I have code OCD. Plus, the thread on this list came from somebody
trying to puzzle out what the code did, and it's very repetitive code,
so I wanted to make it simpler and clearer.
Anyway, the tests pass, but the patch hasn't been applied, because
there's a question raised, which is why does it send the correct
binding when it's defined in some other method. On the one hand the
answer seems obvious, because it's a method on Kernel, but honestly I
can't understand it as well as I think I do, because I can't explain
it beyond that "obvious" point. How do I explain how this code works?
How does this code work? I know it works, but I can't actually explain
it.
eval(IO.read(file), binding, file)
I changed it to a method:
def eval_file_with_binding(file)
eval(IO.read(file), binding, file)
end
It appeared twice in Rails, so refactoring it was kind of overkill,
but I have code OCD. Plus, the thread on this list came from somebody
trying to puzzle out what the code did, and it's very repetitive code,
so I wanted to make it simpler and clearer.
Anyway, the tests pass, but the patch hasn't been applied, because
there's a question raised, which is why does it send the correct
binding when it's defined in some other method. On the one hand the
answer seems obvious, because it's a method on Kernel, but honestly I
can't understand it as well as I think I do, because I can't explain
it beyond that "obvious" point. How do I explain how this code works?
How does this code work? I know it works, but I can't actually explain
it.