From: Chris Hall Date: 2007-09-20T03:12:27+09:00 Subject: Re: exceptions and eval'ing a string sorry, there's a typo in the example, that eval line should read @t = eval(IO.read("test.task")) rather than @t = eval("test.task") problem still stands. Chris Hall wrote: > Here's my situation > > > I have a setup such as: > > ----task.rb---- > class Task > def initialize(name, &action) > @name = name > @action = action > end > > def run > @action.call(self) > end > end > > ----task_runner.rb---- > require 'task' > > t = Task.new('task_1') { |t| puts t.name } > t.run # => thing > > > what i am now trying to do is put the Task creation code inside a file > and eval that as a string > > ----thing.task---- > Task.new('task_1') P |t| puts t.name } > > > ----task_runner.rb---- > require 'task' > def load_task > @t = eval('thing.task') > end > > @t = nil > load_task > @t.run > > and this works...however, the difference is that if an exception is > thrown as part of the Task's action (when it is run) eval craps out with > an exception like > > (eval):15 > > and it brings down the entire script, which is a bad thing because i'm > running each task in a thread. this doesn't happen obviously when i'm > not eval'ing. > > can someone explain to me what is going on? I'm thinking it's a > scoping/context thing, but i'm not really sure. > > Chris -- Posted via http://www.ruby-forum.com/.