Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Overview

Extensions to class String.

Author:

  • Thorsten Kummerow (@thomerow)

Instance Method Summary collapse

Instance Method Details

#remove_first_and_lastString

Removes the first and last characters from a string and returns the manipulated string.

Returns:

  • (String)

    The string without its first and last characters.



21
22
23
24
25
26
27
# File 'lib/core_ext/string.rb', line 21

def remove_first_and_last 
  if self.length == 0 then return '' end
  result = self.dup
  result[0] = ''
  if result.length > 0 then result[result.length - 1] = '' end
  return result
end