Skip to content

Commit db3fbfe

Browse files
committed
Add Kernel#pp
The implementation tries to use console.log directly to pretty inspect object inside browsers. This is in some ways non compliant with MRI, but given the interactive ouptut of console log is much prettier seems a sensible implementation.
1 parent 9549255 commit db3fbfe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

stdlib/pp.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
module Kernel
22
def pretty_inspect; inspect; end
3+
4+
if `(typeof console === "undefined" || typeof console.log === "undefined")`
5+
alias :pp :p
6+
else
7+
def pp *args
8+
args.each { |obj| `console.log(obj);` }
9+
args.length <= 1 ? args[0] : args
10+
end
11+
end
312
end

0 commit comments

Comments
 (0)