Conversation
Prototype for untangling Irb, Context and WorkSpace: - Add WorkspaceStack, which owns the workspace stack and its invariants (fixed home workspace, never empty, helper methods loaded whenever a workspace becomes current). Context delegates to it, and the methods that ext/workspaces.rb and ext/change-ws.rb used to monkey patch into Context now live in Context itself. - Fix `chws` with no argument not returning home after `pushws`, caused by home_workspace being memoized lazily from the current workspace. - Stop reading Context's ivars from the outside (pushws, Irb's suspend_input_method). - Move from_binding onto Context and statement dispatch onto Irb, which passes itself to commands. Internal code no longer reaches Irb via Context#irb (only multi-irb still does). - Extract WorkSpace.base_binding from WorkSpace#initialize. - Remove the dead Context#workspace_home reader and IrbLoader#old. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
Measure's initialize override was a no-op, and it was the only thing that forced the setter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
Context#irb is always the Irb running the command, so injecting it separately added an API without changing behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
debug.gem prepends a patch to IRB::Context#evaluate to restart its threads around each evaluation, so moving dispatch to Irb broke the debugger's IRB console. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors IRB's workspace management by extracting workspace stack logic into a dedicated
WorkspaceStackclass. This improves code organization, encapsulation, and makes workspace operations more explicit and testable.Key Changes
New
WorkspaceStackclass (lib/irb/workspace_stack.rb):push,pop,swap,replace, andwith(context manager)Enumerablefor iteration supportRefactored
Contextclass:@workspace_stackarray with@workspaces(WorkspaceStack instance)from_bindingparameter toinitializeto track if context was started byBinding#irbfrom_binding?logic from IRB class to Contexthome_workspaceaccessor to get the initial workspacechange_workspaceandpush_workspacemethods directly into Context (previously in extension files)evaluatemethod logic to IRB class asevaluate_statementRefactored
WorkSpaceclass:base_bindinginitializeto use the newbase_bindingmethodUpdated
IRBclass:from_bindingto a method that delegates to@context.from_binding?evaluate_statementmethodsuspend_workspaceto useWorkspaceStack#withsuspend_input_methodto use direct property assignment instead ofinstance_evalRemoved extension files:
lib/irb/ext/change-ws.rb- functionality moved to Contextlib/irb/ext/workspaces.rb- functionality moved to Contextoldmethod fromlib/irb/ext/loader.rbAdded comprehensive tests (
test/irb/test_workspace_stack.rb):Minor improvements:
initializemethod from Measure commandworkspacesaccessorNotable Implementation Details
withmethod provides exception-safe temporary workspace switchinghttps://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U