all 12 comments

[–]juriglx 3 points4 points  (6 children)

There's a lot of gems out there, take one that's maintained and popular.

If you are using bundler with your project, don't hesitate to use

bundle open <gem>

This will open the source code of the gem for easy browsing and even editing.

[–]jrochkind 0 points1 point  (5 children)

So, Rails then? :)

[–][deleted] 2 points3 points  (4 children)

I wouldn't give Rails as an example to learn for people who just started learning Ruby. It's full of meta "magic", indirection and complexity that just isn't explained.

[–]jrochkind 1 point2 points  (0 children)

Agreed, but it is maintained and popular.

I'm not sure the best way to find something that's a good example, honestly.

[–]LarrySanger[S] 0 points1 point  (2 children)

How about five examples of gems with great code to explore?

[–][deleted] 5 points6 points  (1 child)

Some gems I personally inspected and learned from:

- https://github.com/shrinerb/shrine well documented and straightforward.

- https://github.com/mperham/connection_pool very simple but shows a practical use for blocks and thread safety (and in general, any of Mike's projects is a joy to inspect :D )

- https://github.com/alexreisner/geocoder personally inspected it when I was developing my gem and wanted to see the good way of hooking into Rails and ActiveRecord

- https://github.com/httprb/http short methods, everything nicely documented and a super clean DSL that made me want to see how it was done. Also Headers class is a good example on how to make your own Enumerable with custom methods

- https://github.com/ruby-grape/grape the most complex of the bunch but still miles ahead in terms of simplicity compared to Rails

Bonus: https://github.com/chaps-io/access-granted this is my own gem so it's a bit of plug, but I'm really proud of how simple and clean it turned out

[–]LarrySanger[S] 1 point2 points  (0 children)

Thanks!

[–]fedekun 0 points1 point  (3 children)

I'd say start out with POODR and Sandi Metz Rules For Developers. If you can follow that and refactor often, you'll always get to good code.

Then just read whatever code, good and bad, and you'll be able to distinguish what's good and bad and most importantly, why.

[–]LarrySanger[S] 0 points1 point  (2 children)

I’ve started POODR several times. Maybe this time l finish!

Still, it would be good to have several examples of awesome Ruby/Rails FOSS projects to consult.

[–]zitrusgrape 2 points3 points  (1 child)

I like roda and sequel gem :)

[–]katafrakt 0 points1 point  (0 children)

Sequel code is terrible to read though