2 # irb/workspace-binding.rb -
3 # $Release Version: 0.9.5$
5 # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
6 # by Keiju ISHITSUKA(keiju@ruby-lang.org)
14 # create new workspace. set self to main if specified, otherwise
15 # inherit main from TOPLEVEL_BINDING.
17 if main[0].kind_of?(Binding)
19 elsif IRB.conf[:SINGLE_IRB]
20 @binding = TOPLEVEL_BINDING
22 case IRB.conf[:CONTEXT_MODE]
23 when 0 # binding in proc on TOPLEVEL_BINDING
24 @binding = eval("proc{binding}.call",
28 when 1 # binding in loaded file
30 f = Tempfile.open("irb-binding")
38 when 2 # binding in loaded file(thread use)
39 unless defined? BINDING_QUEUE
42 IRB.const_set("BINDING_QUEUE", SizedQueue.new(1))
43 Thread.abort_on_exception = true
45 eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
49 @binding = BINDING_QUEUE.pop
51 when 3 # binging in function on TOPLEVEL_BINDING(default)
52 @binding = eval("def irb_binding; binding; end; irb_binding",
59 @main = eval("self", @binding)
62 IRB.conf[:__MAIN__] = @main
65 @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
68 @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
70 IRB.fail CantChangeBinding, @main.inspect
74 eval("_=nil", @binding)
80 def evaluate(context, statements, file = __FILE__, line = __LINE__)
81 eval(statements, @binding, file, line)
84 # error message manipulator
85 def filter_backtrace(bt)
86 case IRB.conf[:CONTEXT_MODE]
88 return nil if bt =~ /\(irb_local_binding\)/
90 if(bt =~ %r!/tmp/irb-binding! or
91 bt =~ %r!irb/.*\.rb! or
96 return nil if bt =~ /irb\/.*\.rb/
98 return nil if bt =~ /irb\/.*\.rb/
99 bt.sub!(/:\s*in `irb_binding'/){""}
104 def IRB.delete_caller