-
-
Save luikore/5516541 to your computer and use it in GitHub Desktop.
Struct with cleaner inspect and pretty print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class S < Struct | |
def inspect | |
pretty_inspect # may be not defined yet, don't alias | |
end | |
def pretty_print(q) | |
q.group(1, sprintf("<%s", PP.mcall(self, Kernel, :class).name.split('::').last), '>') { | |
q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member| | |
q.breakable | |
q.text member.to_s | |
q.text '=' | |
q.group(1) { | |
q.breakable '' | |
q.pp self[member] | |
} | |
} | |
} | |
end | |
def pretty_print_cycle(q) | |
q.text sprintf("<%s:...>", PP.mcall(self, Kernel, :class).name.split('::').last) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment