Download its source code into a separate folder (perhaps from github). Then modify your Gemfile to point to the source directly so that you can edit it and test your changes directly.
For example, let’s say that you want to edit the secure_headers gem and that you’ve cloned it into ~/workspace/secureheaders. Then you can use the following in your Gemfile:
gem 'secure_headers', :path => "~/workspace/secureheaders"
Then, just modify the source files inside the source tree and you should be able to see your changes applied directly.