Method: Weak::Map#inspect
- Defined in:
- lib/weak/map.rb
#inspect ⇒ String Also known as: to_s
Returns a string containing a human-readable representation of
the weak set, e.g.,
"#<Weak::Map {key1 => value1, key2 => value2, ...}>".
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/weak/map.rb', line 484 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! { |k, _v| k.__id__ }.to_h "#<#{self.class} #{elements}>" ensure object_ids.pop end end |