Last active
January 2, 2016 04:39
-
-
Save epitron/8252073 to your computer and use it in GitHub Desktop.
Turning 'p' into a method that can be run on any object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> module Kernel; alias old_p p; def p(*args); if args.any?; old_p(*args.dup); else; old_p(self); end; nil; end; end | |
=> nil | |
[2] pry(main)> p [1,2,3] | |
[1, 2, 3] | |
=> nil | |
[3] pry(main)> [1,2,3].each(&:p) | |
1 | |
2 | |
3 | |
=> [1, 2, 3] | |
[4] pry(main)> [1,2,3].p | |
[1, 2, 3] | |
=> nil | |
[5] pry(main)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment