Class: Array
Overview
array.rb – Array extensions
Author: Russell Sim Copyright © 2024 Russell Sim SPDX-License-Identifier: MIT
Direct Known Subclasses
Instance Method Summary collapse
-
#rider_display ⇒ Object
Return a
string
representation of the object in a consistent manner that will not be excessivly long.
Instance Method Details
#rider_display ⇒ Object
Return a string
representation of the object in a consistent manner that will not be excessivly long.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rider_server/core_ext/array.rb', line 13 def rider_display max_length = 50 sample = +"" dup.slice(0, 3).each do |item| str = item.inspect remaining = max_length - (sample.length + str.length) # Truncate the string, and preserve any terminators if sample.length >= max_length # Ignore item elsif remaining < 0 terminator = ["]", '"', "'", ">"].member?(str[-1]) ? str[-1] : "" sample << (str.dup[0, max_length] + "..." + terminator) else sample << str.dup sample << ", " end end "#<#{self.class}: [#{sample}] size: #{length}>" end |