Bugbye not loading its output in pry

I installed byebug with the command given in the Alpha lesson and loaded primes.rb in pry and then ran prime?(5). The byebug output isn’t showing at all. Here’s the full rundown of what I ran in terminal:

Kevins-MacBook-Pro-2:r Kevin$ gem install byebug
Building native extensions.  This could take a while...
Successfully installed byebug-9.0.6
Parsing documentation for byebug-9.0.6
Done installing documentation for byebug after 1 seconds
1 gem installed
Kevins-MacBook-Pro-2:r Kevin$ pry
[1] pry(main)> load 'primes.rb'
=> true
[2] pry(main)> prime?(5)
=> false
[3] pry(main)> 

I installed byebug and ensured that my primes.rb file included require ‘byebug’ on top. Despite doing this, it’s not showing the byebug output it’s supposed to be showing.

what my primes.rb file looks like:

# primes.rb

require 'byebug'

def prime?(num)
  (1..num).each do |idx|
    if num % idx == 0
      return false
    end
  end
end

def primes(num_primes)
  ps = []
  num = 1
  while ps.count < num_primes
    primes << num if prime?(num)
  end
end

if __FILE__ == $PROGRAM_NAME
  puts primes(100)
end

Hi kev,

Great question, in order to trigger byebug when running a ruby file you will need to call the byebug method in your code. This will stop your runtime at that line and allow you to use byebug commands to inspect your code. Something like:

def prime?(num)
  byebug
  (1..num).each do |idx|
    if num % idx == 0
      return false
    end
  end
end

You can also use the command debugger instead of byebug. Let me know if you get this to work and if you have any questions. Thanks!

Ah thanks Kevin!

I had read the part about needing to modify the program but assumed the only part we needed to modify was adding require 'byebug'.

Thanks for pointing out the other required line in the method byebug (debugger works too).