Skip to content

Commit

Permalink
Let p and pp return the argument
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jan 5, 2017
1 parent ba5c2b0 commit d7c2f28
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/kernel.cr
Expand Up @@ -83,33 +83,35 @@ def puts(*objects) : Nil
end

# Pretty prints *object* to STDOUT followed
# by a newline.
# by a newline. Returns *object*.
#
# See also: `Object#pretty_print(pp)`.
def p(object) : Nil
def p(object)
PrettyPrint.format(object, STDOUT, 79)
puts
object
end

# Pretty prints each object in *objects* to STDOUT, followed
# by a newline.
# by a newline. Returns *objects*.
#
# See also: `Object#pretty_print(pp)`.
def p(*objects) : Nil
def p(*objects)
objects.each do |obj|
p obj
end
objects
end

# Pretty prints each object in *objects* to STDOUT, followed
# by a newline.
# by a newline. Returns *objects*.
#
# ```
# p foo: 23, bar: 42 # prints "{foo: 23, bar: 42}"
# p foo: 23, bar: 42 # => {foo: 23, bar: 42}
# ```
#
# See `Object#pretty_print(pp)`
def p(**objects) : Nil
def p(**objects)
p(objects)
end

Expand Down

0 comments on commit d7c2f28

Please sign in to comment.