Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Created November 22, 2012 02:32
Show Gist options
  • Save tkfm-yamaguchi/4129126 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/4129126 to your computer and use it in GitHub Desktop.
Customize pp output
require 'pp'
class PP
module PPMethods
def seplist(list, sep=nil, iter_method=:each) # :yield: element
sep ||= lambda { comma_breakable }
first = true
nest(1) {
breakable
list.__send__(iter_method) {|*v|
if first
first = false
else
sep.call
end
yield(*v)
}
nest(-2) {
breakable
}
}
end
end
end
obj = {"data"=>{1=>"one", 2=>"two", 3=>"three"}, "name"=>["homu", "mami", "mado", "miki", "saku"]}
PP.pp obj, $>, 20
{
"data"=>
{
1=>"one",
2=>"two",
3=>"three"
},
"name"=>
[
"homu",
"mami",
"mado",
"miki",
"saku"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment