Skip to content

Instantly share code, notes, and snippets.

@jasoares
Last active December 11, 2015 22:19
Show Gist options
  • Save jasoares/4669181 to your computer and use it in GitHub Desktop.
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 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