Method: Weak::Set#inspect
- Defined in:
- lib/weak/set.rb
#inspect ⇒ String Also known as: to_s
Returns a string containing a human-readable representation of
the weak set, e.g., "#<Weak::Set {element1, element2, ...}>".
476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/weak/set.rb', line 476 def inspect object_ids = (Thread.current[INSPECT_KEY] ||= []) return "#<#{self.class} {...}>" if object_ids.include?(object_id) object_ids << object_id begin elements = to_a.sort_by!(&:__id__).inspect[1..-2] "#<#{self.class} {#{elements}}>" ensure object_ids.pop end end |