user27931
user27931

Reputation: 81

binding.pry being skipped in Ruby

binding.pry is not catching for me in some situations.

For instance, when I run this code using ruby programtorun.rb in the terminal, it doesn't open up a Pry session.

require 'pry'

class Foo
  def bar
    boo = true
    binding.pry
  end
end

f = Foo.new
f.bar

I tried reinstalling Pry but the problem persisted.

Upvotes: 2

Views: 1999

Answers (1)

JTG
JTG

Reputation: 8826

The problem is that binding.pry stops on the next line to be executed in your program. Your next line is non-existent. binding.pry is literally the last thing you call before your script ends.

Changing

class Foo
  def bar
    boo = true
    binding.pry
  end
end

to

class Foo
  def bar
    binding.pry
    boo = true
  end
end

caused it to stop for me at boo=true.

Upvotes: 2

Related Questions