How do I use pry in bin/console in a Ruby project

125 views Asked by At

I am very new to Ruby... just started learning it a couple of weeks ago. I have a project set up in the picture below: Ruby Project Setup

The main.rb file is a module with basic arithmetic methods, for example,

module Main
  def sum(x, y)
    return x + y
  end

  def diff(x, y)
    return x - y
  end
...

as well as division and multiplication.

I wanted to create an interactive prompt, using pry, to experiment the program. From my knowledge I need to setup pry in the bin/console file in the project.

After a bit of research, I found that if I setup my bin/console file to have the following code:

#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "../lib/main.rb"

require "pry"
Pry.start()

Then I just need to enter ./bin/console into my terminal to run the pry debugger.

I setup my bin/console file as above, but when I enter ./bin/console into my terminal, it just asks me which app to open the file with.

Is there another way of doing this? What exactly have I done wrong here?

If there is any more info I can give, let me know. Thanks

0

There are 0 answers