Class: String

### Home Classes Methods

### In Files

- lib/logging/utils.rb

### Parent

Object

### Methods

- #shrink

### Files

- History.txt

### Class/Module Index

Quicksearch

- Logging
- Logging::Appender
- Logging::Appenders
- Logging::Appenders::Buffering
- Logging::Appenders::File
- Logging::Appenders::IO
- Logging::Appenders::RollingFile
- Logging::Appenders::RollingFile::Roller
- Logging::Appenders::Stderr
- Logging::Appenders::Stdout
- Logging::Appenders::StringIo
- Logging::Appenders::Syslog
- Logging::ColorScheme
- Logging::Filter
- Logging::Filters
- Logging::Filters::Level
- Logging::Layout
- Logging::Layouts
- Logging::Layouts::Basic
- Logging::Layouts::Parseable
- Logging::Layouts::Pattern
- Logging::Logger
- Logging::MappedDiagnosticContext
- Logging::NestedDiagnosticContext
- Logging::Proxy
- Logging::RailsCompat
- Logging::Repository
- Logging::Repository::Singleton
- Logging::RootLogger
- RSpec
- RSpec::Core
- RSpec::Core::Configuration
- RSpec::LoggingHelper
- RSpec::LoggingHelper
- Spec
- Spec::Runner
- Spec::Runner::Configuration
- Object
- Object::LoggingHelper
- File
- FileUtils
- Module
- ReentrantMutex
- String

No matching classes.

# String

### Public Instance Methods

shrink( width, ellipses = '...' ) #=> string click to toggle source

Shrink the size of the current string to the given width by removing characters from the middle of the string and replacing them with ellipses. If the width is greater than the length of the string, the string is returned unchanged. If the width is less than the length of the ellipses, then the ellipses are returned.

    # File lib/logging/utils.rb, line 17
    def shrink( width, ellipses = '...')
      raise ArgumentError, "width cannot be negative: #{width}" if width < 0

      return self if length <= width

      remove = length - width + ellipses.length
      return ellipses.dup if remove >= length

      left_end = (length + 1 - remove) / 2
      right_start = left_end + remove

      left = self[0,left_end]
      right = self[right_start,length-right_start]

      left << ellipses << right
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.