class Binding

def irb(show_code: true)

See IRB@IRB+Usage for more information.


Cooked potato: true
irb(#):005:0> exit

output printed to standard output in this example:
resume execution where +binding.irb+ had paused it, as you can see from the
You can exit the IRB session with the +exit+ command. Note that exiting will

=> true
irb(#):004:0> @cooked = true
=> ".../2.5.1/lib/ruby/2.5.0/irb/workspace.rb:85:in `eval'"
irb(#):003:0> caller.first
=> Potato
irb(#):002:0> self.class
=> false
irb(#):001:0> @cooked

context. This allows you to debug without having to run your code repeatedly:
You can type any valid Ruby code and it will be evaluated in the current

irb(#):001:0>

9: Potato.new
8:
7: end
6: end
5: puts "Cooked potato: #{@cooked}"
=> 4: binding.irb
3: @cooked = false
2: def initialize
1: class Potato

From: potato.rb @ line 4 :

$ ruby potato.rb

+binding.irb+ is called, and you will see the following:
Running ruby potato.rb will open an IRB session where

Potato.new

end
end
puts "Cooked potato: #{@cooked}"
binding.irb
@cooked = false
def initialize
class Potato

Given a Ruby file called +potato.rb+ containing the following code:


the current scope, and mutate state if you need to.
interactive debugging. You can call any methods or variables available in
Opens an IRB session where +binding.irb+ is called which allows for
def irb(show_code: true)
  IRB.setup(source_location[0], argv: [])
  workspace = IRB::WorkSpace.new(self)
  STDOUT.print(workspace.code_around_binding) if show_code
  binding_irb = IRB::Irb.new(workspace)
  binding_irb.context.irb_path = File.expand_path(source_location[0])
  binding_irb.run(IRB.conf)
  binding_irb.debug_break
end