I'm evaluating a ruby script against a testing DSL that I wrote. Now I
would have loved to run the scripts at the toplevel, but the
contamination of the Object class makes that infeasible. So I run them
within a Scope object. Basically:
class Scope < Module
def initialize
extend self
end
def execute(script, filename)
eval(script, binding, filename)
end
end
My problem arises when a script uses a constant that isn't defined and
the error message looks like this:
I ran into this same problem today myself, although attempting something
different. I wanted to stylize a constant name with a bang! Our company's
name happens to be stylized with a bang, so I thought I'd be silly and try
to translate that into Ruby itself (I was inspired by Rainbows!)
On Fri, Oct 29, 2010 at 4:06 PM, Intransition <transfire@gmail.com> wrote:
I'm evaluating a ruby script against a testing DSL that I wrote. Now I
would have loved to run the scripts at the toplevel, but the
contamination of the Object class makes that infeasible. So I run them
within a Scope object. Basically:
class Scope < Module
def initialize
extend self
end
def execute(script, filename)
eval(script, binding, filename)
end
end
My problem arises when a script uses a constant that isn't defined and
the error message looks like this:
Why not add a const_missing() to your Scope class and explicitly lookup
the constant on Object there, which will fail, and so the error will be
as if a top-level constant wasn't found.