Skip to content

Extract WorkspaceStack and loosen Context's coupling to Irb and WorkSpace - #1259

Open
st0012 wants to merge 1 commit into
masterfrom
claude/irb-context-workspace-coupling-no0j43
Open

st0012 wants to merge 1 commit into
masterfrom
claude/irb-context-workspace-coupling-no0j43

Conversation

@st0012

@st0012 st0012 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Why

Irb, Context and WorkSpace reach into each other a lot. The clearest example is the workspace stack. It lives in Context, but several places change it directly, and each one has to remember the rules itself, like keeping the home workspace and loading helper methods. Some forget.

That already caused a bug: pushws foo followed by a bare chws stays on foo instead of going back to main.

Direction

Each class should own one thing:

  • WorkSpace: a binding and its main object
  • WorkspaceStack (new): moving between workspaces and keeping the stack's rules
  • Context: the session's settings and state
  • Irb: the loop that reads, evaluates and prints input

This PR takes the first steps:

  • Add WorkspaceStack and make it the only place that changes the stack. This fixes the chws bug.
  • Move the workspace methods from ext/workspaces.rb and ext/change-ws.rb into Context, and delete those files.
  • Store from_binding on Context, so it no longer asks Irb.
  • Stop reading Context's instance variables from outside it.
  • Extract WorkSpace.base_binding from WorkSpace#initialize.

Behavior changes

  • irb_load file, true now gets helper methods like conf inside the loaded file. Before, this raised a NameError.
  • irb/ext/workspaces and irb/ext/change-ws are removed. Code that still requires them will load the old copies bundled with Ruby, which break pushws, popws and chws, so drop those requires.

Generated by Claude Code

@st0012 st0012 changed the title Refactor workspace management into dedicated WorkspaceStack class Extract WorkspaceStack and loosen Context's coupling to Irb and WorkSpace Oct 8, 2026
…pace

The workspace stack lived in Context, but several places changed it
directly, and each had to remember the rules itself, like keeping the
home workspace and loading helper methods. That caused a bug: `pushws
foo` followed by a bare `chws` stayed on `foo` instead of going back to
main.

- Add WorkspaceStack and make it the only place that changes the stack.
- Move the workspace methods from ext/workspaces.rb and ext/change-ws.rb
  into Context, and delete those files.
- Store from_binding on Context, so it no longer asks Irb.
- Stop reading Context's instance variables from outside it.
- Extract WorkSpace.base_binding from WorkSpace#initialize.
- Remove dead code: Context#workspace_home, IrbLoader#old and
  Measure#initialize.

A file loaded with `irb_load file, true` now also gets helper methods
like `conf`.
@st0012
st0012 force-pushed the claude/irb-context-workspace-coupling-no0j43 branch from 2ebded8 to b827bf7 Compare October 8, 2026 21:06
@st0012
st0012 marked this pull request as ready for review October 8, 2026 21:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants