Module: RubyOnAsteroids::CoreExt::String::Accessing

Defined in:
lib/ruby_on_asteroids/core_ext/string/accessing.rb

Overview

Useful extensions to String class related to accessing the string content

Instance Method Summary collapse

Instance Method Details

#but_last(num_of_characters = 1) ⇒ Object

Returns a copy of the original string object with the last ‘num_of_characters` being removed. If `num_of_characters` is not provided, it defaults to removing the last character. When the original string is empty, returns an empty string



11
12
13
# File 'lib/ruby_on_asteroids/core_ext/string/accessing.rb', line 11

def but_last(num_of_characters = 1)
  self[0..-(1 + num_of_characters)]
end