Last active
December 11, 2015 22:19
-
-
Save jasoares/4669181 to your computer and use it in GitHub Desktop.
Override default Object#to_s preserving class and encoded id like #<Nokogiri::XML::Element:0x11ab674 @var="123" ...
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
# This reimplementation produces the following sample result | |
# => #<Object:0x000000018436d0 @var=3> | |
def to_s | |
"#<%s:%#0.14x @var=%s>" % [self.class, self.__id__.abs*2, var] | |
end | |
# It is also possible to minify it by tweaking precision an getting rid | |
# of all those zeros like so: | |
# => #<Object:0x18436d0 @var=3> | |
def to_s | |
"#<%s:%#x @var=%s>" % [self.class, self.__id__.abs*2, var] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment