> You could hook into Object#method_missing and
> Object.const_missing to handle NameErrors before
> they happen, although I'd try to redesign my code
> in any possible way before resorting to such methods.

Hmmm. My approach would only work easily if I'd
be able to continue loading the whole ruby file
in question. I am not sure I understood this solution
well though - I have to handle NameErrors *before*
they happen?

> An exception always immediately stops execution at the
> point where it is thrown and unwinds the stack until it
> finds a handler (or the process terminates).

Oh I see! Would be neat to be able to suppress that
when one wants to, with the rest of the code continued
to be read and interpreted.

> Basically you could wrap every individual section with
> "begin rescue end". Then such a section would be the
> smallest part which could fail. Alternatively you could
> split the file in multiple parts and have a specific
> implementation of "load" which ignores errors:

> def load_ignorant(s)
>  load(s)
> rescue Exception
>   # eat it
> end

Hmm you mean wrap the file into different smaller files
and load these? Probably feasible. I'd however like to
keep a constraint as in having a large ruby file available
already. It also sounds like too much work to split the
file in question up.

> Why do you want to do that? That sounds like a bad plan
> to me since you won't notice any issues and your
> application's state is unclear.

The demo code in question just shows that the ruby file
only has invalid calls to non-existent methods. But
otherwise, it is fine. I would argue that by definition
there can not be any issues with it (from that faulty
ruby file) because after all it is faulty anyway and
there are only two states for it - either it contains
valid ruby code or it is invalid (in which case it should
be ignored).

Consider it a crazy wish for purposely sloppy programming
where perfection can stop at 40% rather than go for the
usual 100%.

As for the reason why I want to do that - I want to run
invalid code which could become partially valid, rather
than stopped when encountering an Exception.

Consider it as something that will never find its way
into any program.

If it is too cumbersome to achieve though then this idea
already falls short.

-- 
Posted via http://www.ruby-forum.com/.