DEV Community

YC Yap for PostCo

Posted on

5 1

[TIL] Debugging external gem in Ruby

Sometimes there comes a time where an external gem that you installed is not behaving as expected. It was not until a week ago that i learned from my colleague that you can actually open the gems to inspect the code inside the gem and debugging it using a debugger.

Firstly, you can open the gem by running.

bundle open countries

Identify the part of the code which you wish to debug. For example i would like to understand why a method in the gem 'countries' is not returning values as expected.

Start inserting calls to debugger in places you expect it to call.

require 'byebug'

module ISO3166
  class Country
    def initialize(country_data)
      byebug
      @country_data_or_code = country_data
      reload
    end
  end
end

Using debugger allows you to better understand the code execution, so that variables which are causing the unexpected behaviours during the execution call be be inspected.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay