Skip to content

Instantly share code, notes, and snippets.

@noprompt
Created August 25, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noprompt/9534e84cdc68f1781506fffdeb7c96e9 to your computer and use it in GitHub Desktop.
Save noprompt/9534e84cdc68f1781506fffdeb7c96e9 to your computer and use it in GitHub Desktop.
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