Skip to content

Commit

Permalink
Add Kernel#pp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elia committed Nov 15, 2013
1 parent 9549255 commit db3fbfe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stdlib/pp.rb
@@ -1,3 +1,12 @@
module Kernel
def pretty_inspect; inspect; end

if `(typeof console === "undefined" || typeof console.log === "undefined")`
alias :pp :p
else
def pp *args
args.each { |obj| `console.log(obj);` }
args.length <= 1 ? args[0] : args
end
end
end

3 comments on commit db3fbfe

@adambeynon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeah, sounds the best idea.

@elia
Copy link
Member Author

@elia elia commented on db3fbfe Nov 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐸

@meh
Copy link
Member

@meh meh commented on db3fbfe Nov 15, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.