Skip to content

Commit fb20cc3

Browse files
committed
Fix eval_path and history support in PlainBackend
1 parent 0da5bc0 commit fb20cc3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/iruby/backend.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module IRuby
33

44
module History
55
def eval(code, store_history)
6-
b = TOPLEVEL_BINDING
6+
b = eval_binding
77

88
b.local_variable_set(:_ih, In) unless b.local_variable_defined?(:_ih)
99
b.local_variable_set(:_oh, Out) unless b.local_variable_defined?(:_oh)
@@ -39,10 +39,17 @@ def initialize
3939
require 'irb'
4040
require 'irb/completion'
4141
IRB.setup(nil)
42-
@irb = IRB::Irb.new
42+
@main = TOPLEVEL_BINDING.eval("self").dup
43+
@workspace = IRB::WorkSpace.new(@main)
44+
@irb = IRB::Irb.new(@workspace)
45+
@eval_path = @irb.context.irb_path
4346
IRB.conf[:MAIN_CONTEXT] = @irb.context
4447
end
4548

49+
def eval_binding
50+
@workspace.binding
51+
end
52+
4653
def eval(code, store_history)
4754
@irb.context.evaluate(code, 0)
4855
@irb.context.last_value
@@ -67,6 +74,10 @@ def initialize
6774
reset
6875
end
6976

77+
def eval_binding
78+
TOPLEVEL_BINDING
79+
end
80+
7081
def eval(code, store_history)
7182
Pry.current_line = 1
7283
@pry.last_result = nil
@@ -99,7 +110,7 @@ def complete(code)
99110
end
100111

101112
def reset
102-
@pry = Pry.new(output: $stdout, target: TOPLEVEL_BINDING)
113+
@pry = Pry.new(output: $stdout, target: eval_binding)
103114
end
104115
end
105116
end

0 commit comments

Comments
 (0)