Skip to content

Instantly share code, notes, and snippets.

@mnaberez
Created September 3, 2012 00:04
Show Gist options
  • Save mnaberez/3605753 to your computer and use it in GitHub Desktop.
Save mnaberez/3605753 to your computer and use it in GitHub Desktop.
More compact output from PP.singleline_pp by omitting spaces
require 'pp'
class PP
class CompactSingleLine < SingleLine
# output comma separators as "," instead of ", " to save bytes
def comma_breakable
text ","
end
end
def PP.compact_singleline_pp(obj, out=$>)
q = CompactSingleLine.new(out)
q.guard_inspect_key {q.pp obj}
q.flush
out
end
end
PP.singleline_pp([1, 2, 3, {:foo => 'bar'}], "")
# => "[1, 2, 3, {:foo=>\"bar\"}]"
PP.compact_singleline_pp([1, 2, 3, {:foo => 'bar'}], "")
# => "[1,2,3,{:foo=>\"bar\"}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment