Skip to content

Commit 8ad21bc

Browse files
makenowjustAry Borenszweig
authored and
Ary Borenszweig
committed
pp: fixed to return value like 'p'
Current implementation of pp returns `nil` always, but `p` returns printed value. It fixes to return printed value of 'pp'.
1 parent a5ac971 commit 8ad21bc

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/macros.cr

+15-7
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,25 @@ macro pp(*exps)
9999
{% exp = exps.first %}
100100
%prefix = "#{{{ exp.stringify }}} # => "
101101
::print %prefix
102-
PrettyPrint.format({{exp}}, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
102+
%object = {{exp}}
103+
PrettyPrint.format(%object, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
103104
::puts
105+
%object
104106
{% else %}
105107
%names = { {{*exps.map(&.stringify)}} }
106108
%max_size = %names.max_of &.size
107-
{% for exp, i in exps %}
108-
%prefix = "#{%names[{{i}}].ljust(%max_size)} # => "
109-
::print %prefix
110-
PrettyPrint.format({{exp}}, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
111-
::puts
112-
{% end %}
109+
{
110+
{% for exp, i in exps %}
111+
begin
112+
%prefix = "#{%names[{{i}}].ljust(%max_size)} # => "
113+
::print %prefix
114+
%object = {{exp}}
115+
PrettyPrint.format(%object, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
116+
::puts
117+
%object
118+
end,
119+
{% end %}
120+
}
113121
{% end %}
114122
end
115123

0 commit comments

Comments
 (0)