I have two questions.
How do I contribute to a ruby gem? Do I just locate it's repo and make a pull request? Or are there more formal procedures?
Also, what if I've made some very useful methods but I know they're not perfect (but they're still very useful and could save others a lot of time). Is it worth submitting changes that are known to be imperfect?
These are great questions. Really, you should open an issue before you do any work because the maintainer of the gem is the one who will have to support your code.
Ask them if they're interested in adding X feature and if they'd be willing to accept your pull request. You can also ask them about how you should approach it, how to write tests, and how to handle those imperfect situations. They'll usually be more than happy to help you through it.
Oh great. Thanks!
What happens if the maintainer doesn't like your idea / code? Can they make suggestions? Do maintainers ever feel obliged to include someone's work just out of guilt? Or will they generally come back with suggestions to improve the code ?
Yeah, it can get a little weird sometimes. You might suggest a good feature, but they might not use it or know how it works which makes for a reason they might not want to accept a feature. Hopefully you'd be able to help out and maintain it, that's very helpful.
It's really common for them to come back with suggestions to improve the code. Especially because they have to maintain it, they want to make sure it's similar style to their existing code so it's easy to understand. It's usually a back-and-forth discussion about how to implement things which is great.
One of the most helpful things you can do to get involved is to help out on all the other issues reviewing other PRs or issues or documentation. Then the maintainer gets to work with you a bit and the rapport helps when proposing features.
An example of a PR discussion of new features is this one on Stimulus. It came from the original developers, but they want to see what the community thinks and if it will be helpful or not. https://github.com/stimulusjs/stimulus/pull/202
Make a pull request. That is generally the accepted means to contribute. If the maintainer finds value in the pull request, they can merge it in. If you create a pull request and the maintainer rejects your changes, you are free to create a new gem containing your code or even fork the gem to create a new version.
When you create a pull request, it would be best if you submit the relevant code meeting the standards of the current gem. If you submit sloppy code that is hard to follow it will generally get rejected.
Join 20,000+ developers who get early access to new screencasts, articles, guides, updates, and more.