awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

sort_vars option #295

Closed aars closed 7 years ago

aars commented 7 years ago

Hi!

First off, great lib! Thanks! I was missing this feature, so here is a PR.

Motivation: To unclutter/customize the output of pp and/or Object.inspect I override instance_variables to return only the instance variables I care about, in the order I care about them. For example, if one of the instance variables is a somewhat large Hash, you might want to print that last, as to improve readability of all other vars.

pp was easily forced to not sort the array by monkeypatching the sort method for the specific array with instance variables (or, their keys). But AwesomePrint maps the vars to a new array and sorts them later. This PR adds a sort_vars option (default true, nothing breaks) to disable this sorting.

Let me know what you think. If anything can be approved if you like the feature, etc.

Cheers!

gerrywastaken commented 7 years ago

Thanks for this pull request. Very well explained and easy to follow. I love PRs like this. :)