How do I drop to the IRB prompt from a running script?

后端 未结 6 628
再見小時候
再見小時候 2020-12-23 14:19

Can I drop to an IRB prompt from a running Ruby script?

I want to run a script, but then have it give me an IRB prompt at a point in the program with the current sta

6条回答
  •  情书的邮戳
    2020-12-23 14:30

    apparently it requires a chunk of code to drop into irb.

    Here's the link (seems to work well).

    http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application

    
    require 'irb'
    
    module IRB
      def self.start_session(binding) # call this method to drop into irb
        unless @__initialized
          args = ARGV
          ARGV.replace(ARGV.dup)
          IRB.setup(nil)
          ARGV.replace(args)
          @__initialized = true
        end
    
        workspace = WorkSpace.new(binding)
    
        irb = Irb.new(workspace)
    
        @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
        @CONF[:MAIN_CONTEXT] = irb.context
    
        catch(:IRB_EXIT) do
          irb.eval_input
        end
      end
    end
    

提交回复
热议问题