Skip to content

Instantly share code, notes, and snippets.

@luikore
Created May 4, 2013 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luikore/5516541 to your computer and use it in GitHub Desktop.
Save luikore/5516541 to your computer and use it in GitHub Desktop.
Struct with cleaner inspect and pretty print
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