summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
authorStan Lo <[email protected]>2024-03-01 23:51:14 +0800
committergit <[email protected]>2024-03-01 15:51:29 +0000
commit57ca5960ad207beb0c4f2788df0e74f8cc6b7cac ()
tree32e39f039b6b53a967f37ed52bd10b2b84abd36e /lib/irb/context.rb
parent162e13c884a1764e6cf6e62407e607d18f29eecc (diff)
[ruby/irb] Restructure workspace management
(https://.com/ruby/irb/pull/888) * Remove dead irb_level method * Restructure workspace management Currently, workspace is an attribute of IRB::Context in most use cases. But when some workspace commands are used, like `pushws` or `popws`, a workspace will be created and used along side with the original workspace attribute. This complexity is not necessary and will prevent us from expanding multi-workspace support in the future. So this commit introduces a @workspace_stack ivar to IRB::Context so IRB can have a more natural way to manage workspaces. * Fix pushws without args * Always display workspace stack after related commands are used https://.com/ruby/irb/commit/61560b99b3
-rw-r--r--lib/irb/context.rb26
1 files changed, 18 insertions, 8 deletions
@@ -22,10 +22,11 @@ module IRB
# +other+:: uses this as InputMethod
def initialize(irb, workspace = nil, input_method = nil)
@irb = irb
if workspace
- @workspace = workspace
else
- @workspace = WorkSpace.new
end
@thread = Thread.current
@@ -229,15 +230,24 @@ module IRB
IRB.conf[:HISTORY_FILE] = hist
end
# The top-level workspace, see WorkSpace#main
def main
- @workspace.main
end
# The toplevel workspace, see #home_workspace
attr_reader :workspace_home
- # WorkSpace in the current context.
- attr_accessor :workspace
# The current thread in this context.
attr_reader :thread
# The current input method.
@@ -489,7 +499,7 @@ module IRB
# to #last_value.
def set_last_value(value)
@last_value = value
- @workspace.local_variable_set :_, value
end
# Sets the +mode+ of the prompt in this context.
@@ -585,7 +595,7 @@ module IRB
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
last_proc = proc do
- result = @workspace.evaluate(line, @eval_path, line_no)
end
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
_name, callback, arg = item
@@ -596,7 +606,7 @@ module IRB
end
end.call
else
- result = @workspace.evaluate(line, @eval_path, line_no)
end
set_last_value(result)