Sha256: 803fcc0bb676ad1938c8af579500eb03afc8116fe39ea5ecaacc3c115bbce0fd
Contents?: true
Size: 689 Bytes
Versions: 1
Compression:
Stored size: 689 Bytes
Contents
# frozen_string_literal: true module WSDirector module Ext # Extend Object through refinements module Formatting refine ::Object do def truncate(*__rest__) = itself end refine ::String do def truncate(limit) return self if size <= limit "#{self[0..(limit - 3)]}..." end end refine ::Hash do def truncate(limit) str = to_json str.truncate(limit) end end refine ::Float do def duration if self > 1 "#{truncate(2)}s" else "#{(self * 1000).to_i}ms" end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wsdirector-core-1.1.0 | lib/.rbnext/3.2/wsdirector/ext/formatting.rb |