Created
September 3, 2012 00:04
-
-
Save mnaberez/3605753 to your computer and use it in GitHub Desktop.
More compact output from PP.singleline_pp by omitting spaces
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
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