Created
August 25, 2017 21:49
-
-
Save noprompt/9534e84cdc68f1781506fffdeb7c96e9 to your computer and use it in GitHub Desktop.
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
def with_repl_friendly_inspect(&block) | |
x = block.call | |
case x | |
# We don't want to and sometimes can't override the #inspect method | |
# of these classes of values. | |
when Array, | |
Class, | |
FalseClass, | |
Hash, | |
Module, | |
NilClass, | |
Numeric, | |
String, | |
TrueClass | |
x | |
else | |
x.instance_eval do | |
def inspect | |
"#<%s:0x00%x>" % [ | |
self.class.name, | |
self.object_id << 1 | |
] | |
end | |
end | |
end | |
x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment