Skip to content

Commit

Permalink
pp: fixed to return value like 'p'
Browse files Browse the repository at this point in the history
Current implementation of pp returns `nil` always, but `p` returns printed
value. It fixes to return printed value of 'pp'.
  • Loading branch information
makenowjust authored and asterite committed Apr 18, 2017
1 parent a5ac971 commit 8ad21bc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/macros.cr
Expand Up @@ -99,17 +99,25 @@ macro pp(*exps)
{% exp = exps.first %}
%prefix = "#{{{ exp.stringify }}} # => "
::print %prefix
PrettyPrint.format({{exp}}, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
%object = {{exp}}
PrettyPrint.format(%object, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
::puts
%object
{% else %}
%names = { {{*exps.map(&.stringify)}} }
%max_size = %names.max_of &.size
{% for exp, i in exps %}
%prefix = "#{%names[{{i}}].ljust(%max_size)} # => "
::print %prefix
PrettyPrint.format({{exp}}, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
::puts
{% end %}
{
{% for exp, i in exps %}
begin
%prefix = "#{%names[{{i}}].ljust(%max_size)} # => "
::print %prefix
%object = {{exp}}
PrettyPrint.format(%object, STDOUT, width: 80 - %prefix.size, indent: %prefix.size)
::puts
%object
end,
{% end %}
}
{% end %}
end

Expand Down

0 comments on commit 8ad21bc

Please sign in to comment.