Skip to content

IRB doesn't restore context after leaving the nested session #650

@st0012

Description

@st0012

(Originally discovered by @tompng in #575 (comment))

Because IRB overrides the global IRB.conf[:MAIN_CONTEXT] when a new session starts, and doesn't change it back to the previous value when the session exists, IRB doesn't support nested sessions well.

For example:

# test.rb
class Foo
  def self.bar
    binding.irb
  end
end
binding.irb
be ruby test.rb
    4:   end
    5: end
 => 6: binding.irb

irb(main):001:0> irb_context.workspace
=> #<IRB::WorkSpace:0x00000001038f6818 @binding=#<Binding:0x0000000100754760>, @main=main>
irb(main):002:0> Foo.bar

From: test.rb @ line 3 :

    1: class Foo
    2:   def self.bar
 => 3:     binding.irb
    4:   end
    5: end
    6: binding.irb

irb(Foo):001:0> irb_context.workspace # context of the nested session
=> #<IRB::WorkSpace:0x0000000104ef4160 @binding=#<Binding:0x0000000104ef5e70>, @main=Foo>
irb(Foo):002:0> exit # leaving the nested session
=> nil
irb(main):003:0> irb_context.workspace # <==== The context is not restored
=> #<IRB::WorkSpace:0x0000000104ef4160 @binding=#<Binding:0x0000000104ef5e70>, @main=Foo>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions